gsr
09/15/2024, 5:22 PMneokoenig
09/15/2024, 7:55 PMgsr
09/15/2024, 8:02 PMgsr
09/15/2024, 8:03 PMbkbk
09/15/2024, 9:16 PMsession.loggedId
does not exist? Did you perhaps intend to do something like the following?
<!--- Check if user is not logged in --->
<cfif NOT structKeyExists(session, "loggedin") OR (structKeyExists(session, "loggedin") AND session.loggedin eq false)>
<!--- Rotate session ID to prevent session fixation --->
<cfset sessionRotate()>
<cflocation url="login.cfm" addtoken="false">
</cfif>
<!--- Validate user's role for the requested page --->
<cfset var allowedAccess = application.auth.checkUserAccess(session.role_id)>
<cfif NOT allowedAccess>
<cflocation url="unauthorized.cfm" addtoken="false">
</cfif>
aliaspooryorik
session.loggedin = true
gsr
09/16/2024, 10:39 AMaliaspooryorik
session.loggedin
.
You can either in onSessionStart
(of Application.cfc) set session.loggedin = false;
and then set it to true on authentication. That way it always exists so much simpler logic.
Alternatively, just check if it exists of not, so login creates the key (value not important) and log out deletes the key.aliaspooryorik
gsr
09/16/2024, 10:59 AMaliaspooryorik
gsr
09/16/2024, 11:00 AMgsr
09/16/2024, 11:00 AMaliaspooryorik
aliaspooryorik
gsr
09/16/2024, 11:34 AM<!--- List of pages that don't require authentication --->
<cfset var publicPages = "login.cfm,register.cfm,registerSubmit.cfm,logout.cfm,login_check.cfm">
<!--- Check if the current page is public --->
<cfif listFindNoCase(publicPages, listLast(arguments.thePage, "/"))>
<cfreturn true>
</cfif>
<!--- <cfif NOT structKeyExists(session, "loggedin") OR (structKeyExists(session, "loggedin") AND session.loggedin eq false)>
<!--- Rotate session ID to prevent session fixation --->
<cfset sessionRotate()>
<cflocation url="login.cfm" addtoken="false">
</cfif> --->
<!--- Validate user's role for the requested page --->
<cfset var allowedAccess = application.auth.checkUserAccess(session.role_id)>
<cfif NOT allowedAccess>
<cflocation url="unauthorized.cfm" addtoken="false">
</cfif>
on my onSessionStart
<cffunction name="onSessionStart" returntype="void">
<cfset Session.templeNB = StructNew()>
<cfset Session.templeNB.isSuper = false>
<cfset Session.templeNB.isAdmin = false>
<cfset Session.templeNB.isEditor = false>
<cfset Session.templeNB.ContactID=1>
<cfset Session.templeNB.ContactName=''>
<cfset Session.templeNB.ContactFirstLastName=''>
<cfset Session.templeNB.LoggedIn="False">
<cfset Session.templeNB.LogInID=0>
<cfset Session.templeNB.email=''>
<cfset session.loggedin = false>
<cfset session.role_id = 1>
<cfset session.failedLoginAttempts = 0>
<cfset session.lastLoginAttempt = "">
</cffunction>
gsr
09/16/2024, 11:34 AMaliaspooryorik
aliaspooryorik
aliaspooryorik
<!--- List of pages that don't require authentication --->
<cfset var publicPages = "login.cfm,register.cfm,registerSubmit.cfm,logout.cfm,login_check.cfm">
<!--- Check if the current page is public --->
<cfif listFindNoCase(publicPages, listLast(arguments.thePage, "/"))>
<cfreturn true>
</cfif>
<cfif NOT session.loggedin>
<cflocation url="login.cfm" addtoken="false">
<cfreturn true>
</cfif>
<!--- Validate user's role for the requested page --->
<cfif NOT application.auth.checkUserAccess(session.role_id)>
<cflocation url="unauthorized.cfm" addtoken="false">
<cfreturn true>
</cfif>
<cfreturn true>
aliaspooryorik
session.loggedin = false
?aliaspooryorik
login.cfm
does session.loggedin = true
?aliaspooryorik
gsr
09/16/2024, 12:26 PMbkbk
09/16/2024, 5:42 PM<cfset session.loggedin = false>
, my previous login suggestion is then similar to that of Aliaspooryorik:
<cfif not session.loggedin>
<!--- Rotate session ID to prevent session fixation --->
<cfset sessionRotate()>
<cflocation url="login.cfm" addtoken="false">
</cfif>
(2) Anyway, I suspect that that is probably not the code that keeps sending you back to login.cfm. The culprit is probably <cfif NOT application.auth.checkUserAccess(session.role_id)>
.
It is likely that session.loggedin
reverts to false within the function checkUserAccess
If checkUserAccess()
were false then, presumably, session.loggedin
could also be reset to false somewhere within the function. That would explain why you keep ending up at login.cfm. So check the code within the function and make sure it does not reset session.loggedin
to false.gsr
09/16/2024, 5:57 PM