I have simple application that utilizes the CFLOGIN tag. Here is the code:
<cfapplication name="UserPortal" sessionmanagement="yes" setclientcookies="yes" sessiontimeout="#CreateTim
eSpan(0, 0, 15, 0)#" applicationtimeout="#Creat
eTimeSpan(
0, 0, 30, 0)#" loginstorage="session">
<!---Check to see if the application has been initialized. If not, set the neccesary application variables and initialize the app --->
<cflock timeout="30" throwontimeout="no" type="readonly" scope="application">
<cfset IsInitialized = IsDefined('application.Ini
tialized')
>
</cflock>
<cfif not IsInitialized>
<cflock type="exclusive" scope="application" timeout="10">
<cfif not IsDefined('appliaction.Ini
tialized')
>
<cfset application.DSN = "NSLA2">
<cfset application.AdminEmail = "master@nslali.com">
<cfset application.Initialized = true>
</cfif>
</cflock>
</cfif>
<!--- See if User Logged Out --->
<cfif IsDefined("URL.Logout")>
<cflogout>
<cfset URL.Message = "Thank You for Logging Out.">
</cfif>
<cflogin idletimeout="1800" applicationtoken="UserPort
al">
<cfif not IsDefined("cflogin")>
<cfinclude template="login.cfm">
<cfabort>
<cfelse>
<cfif cflogin.Name is "" or cflogin.Password is "">
<cfset URL.Message = "You must enter text in both the Username and Password fields">
<cfinclude template="login.cfm">
<cfabort>
<cfelse>
<cfquery name="ValidateUser" datasource="#application.D
SN#">
SELECT * FROM users WHERE Username = <cfqueryparam value="#cflogin.Name#"
cfsqltype="cf_sql_varchar"
maxlength="255">
</cfquery>
<cfif ValidateUser.Roles is "">
<cfset ValidateUser.Roles = "User">
</cfif>
<cfif (ValidateUser.RecordCount)
and (ValidateUser.Password is Hash(ValidateUser.Salt & cflogin.Password)) and ValidateUser.Roles is "User">
<cfloginuser name="#cflogin.Name#" password="#cflogin.Passwor
d#" roles="#ValidateUser.Roles
#">
<cflock scope="session" timeout="10" type="exclusive">
<cfset session.User = structNew()>
<cfset session.User.ID = #ValidateUser.ID#>
<cfset session.User.FullName = #ValidateUser.FullName#>
<cfset session.User.Company = #ValidateUser.Company#>
</cflock>
<cfelse>
<cfset URL.Message = "Invalid Login. Please Try Again. (You may not sufficient privileges.)">
<cfinclude template="login.cfm">
<cfabort>
</cfif>
</cfif>
</cfif>
</cflogin>
I've tried to incorporate :
<cfif IsDefined("Cookie.CFID") AND IsDefined("Cookie.CFTOKEN"
)>
<cfset cfid_local = Cookie.CFID>
<cfset cftoken_local = Cookie.CFTOKEN>
<cfcookie name="CFID" value="#cfid_local#">
<cfcookie name="CFTOKEN" value="#cftoken_local#">
</cfif>
But what happens is when the browser is closed, it brings the login window up like it should but once the username and password are entered and it tries to access the index page an error pops when I try to call on the variable session.User.FullName. The error states that session.User.FullName does not exist.
I've also tried this:
<cfcookie name="CFID" value="#Session.CFID#">
<cfcookie name="CFTOKEN" value="#Session.CFTOKEN#">
which I found here on this site. But this code doesn't work either. I'm tempted just to leave the users login until the session expires if they don't hit the logout button.
Any suggestions would be great. Or if you find any errors in my code please bring it to my attention.
Thank You,
Matt Toca