Hi I am brand new to coldfusion and trying to create a login that is not authenticated by looking up a username and password - I mean the user logs in with whatever login name they want and are sent to the app but if they try to go to the app without LoggedIn = True, then they are sent back to the mainlogin.cfm page. The problem is that a user can never login - they just loop around - I found out that you cannot use cflocation with cookies and thought session vars are cookies, but a programmer on a mailing list insists session vars are NOT cookies but when I look here - some helpers say they are.
Anyway can someone look at my code and see where I am going wrong - I have tried and tried to fix this (including replacing cflocation with javascript) but still have the same problem.
here is the application.cfm code:
<CFSETTING ENABLECFOUTPUTONLY="Yes">
<CFAPPLICATION NAME="myapp" CLIENTMANAGEMENT="Yes"
SESSIONMANAGEMENT="Yes" SETCLIENTCOOKIES="Yes"
SESSIONTIMEOUT="#CreateTimeSpan(0, 0, 30, 0)#"
APPLICATIONTIMEOUT="#CreateTimeSpan(0, 0, 30, 0)#"
CLIENTSTORAGE="Registry">
<!--- Set the default session state to false so by default,
users are NOT logged into the application --->
<CFLOCK SCOPE="Session" TYPE="Exclusive" TIMEOUT="10">
<CFIF NOT IsDefined("Session.LoggedIn"
>
<CFPARAM NAME="Session.LoggedIn" DEFAULT="False">
</CFIF>
</CFLOCK>
<!--- if the user isn't logged in or they aren't currently on the login
page, send them to the login page --->
<CFLOCK SCOPE="Session" TYPE="ReadOnly" TIMEOUT="10">
<CFIF Not FindNoCase("mainlogin.cfm", CGI.SCRIPT_NAME)AND Not FindNoCase("makeuser1.cfm", CGI.SCRIPT_NAME)>
<CFLOCATION URL="mainlogin.cfm" ADDTOKEN="No">
</CFIF>
</CFLOCK>
<!--- Reset the CFID and CFToken cookies to expire session and client
variables after the user's browser closes --->
<CFIF IsDefined("Cookie.CFID"
AND IsDefined("Cookie.CFToken"
>
<CFCOOKIE NAME="CFID" VALUE="#Cookie.CFID#">
<CFCOOKIE NAME="CFToken" VALUE="#Cookie.CFToken#">
</CFIF>
<!--- check to see if the application has been initialized. If not,
set the necessary application variables and initialize the app
<CFLOCK SCOPE="Application" TYPE="Exclusive" TIMEOUT="10">
<CFIF NOT IsDefined('Application.Initialized')>
<CFSET Application.DSN = "chat1">
<CFSET Application.AdminEmail = "email@email.com">
<!--- Set the application.initialized variable to true so that this
block of code does not execute every time the Application.cfm
file is called --->
<CFSET Application.Initialized = TRUE>
</CFIF>
</CFLOCK>--->
<CFSETTING ENABLECFOUTPUTONLY="No">
here is the mainlogin.cfm code & form:
<cfif #parameterexists(client.user)# is "no">
<cfset client.user = "anonymous">
<cfset client.usercolor = "red">
</cfif>
<form action="makeuser1.cfm">
<font face="verdana, arial" size="2"><b>Your Current login is: </b></font>
<br><input type="text" name="user" size=25 value="<cfoutput>#client.user#</cfoutput>">
<select name="usercolor">
<option value="<cfoutput>#client.usercolor#</cfoutput>" selected>select color
<option value="black"> black
<option value="crimson"> scarlet
<option value="goldenrod"> gold
<option value="cornflowerblue"> blue
<option value="teal"> navy
<option value="deeppink"> pink
<option value="darkmagenta"> purple
<option value="limegreen"> green
<option value="darkgreen"> dark green
<option value="teal"> teal
</select></td></tr><td width="25%"> </td>
<td valign="top" nowrap> <font face="verdana, arial" size="2" color="aqua"><b>You
may change login above</b></font><br>
<font face = verdana, arial, size="2"> (one word, no spaces)</font>
<font face="verdana, arial" size="2"><b>or keep it.</b></font> <br>
</td>
<td valign="bottom" align="left">
<input type="submit" value="login" name="submit">
</td>
<td width="25%"> </td>
</tr></table></form>
here is the makeuser1.cfm code:
<!--- set Session.LoggedIn to True, logging the user in --->
<CFSET session.LoggedIn="TRUE">
<CFLOCK TIMEOUT="30" THROWONTIMEOUT="No" TYPE="EXCLUSIVE" SCOPE="SESSION">
<CFIF #IsDefined(user)#>
<CFSET client.user = #user#>
<CFSET client.usercolor = "#usercolor#">
</CFIF>
</CFLOCK>
<SCRIPT LANGUAGE="JavaScript">
<!--
location.replace("myapp.cfm"
;
//-->
</SCRIPT>
I hope someone will take pity and see if they can see what is wrong - I just cannot find it ~ Thanks, megan
Anyway can someone look at my code and see where I am going wrong - I have tried and tried to fix this (including replacing cflocation with javascript) but still have the same problem.
here is the application.cfm code:
<CFSETTING ENABLECFOUTPUTONLY="Yes">
<CFAPPLICATION NAME="myapp" CLIENTMANAGEMENT="Yes"
SESSIONMANAGEMENT="Yes" SETCLIENTCOOKIES="Yes"
SESSIONTIMEOUT="#CreateTimeSpan(0, 0, 30, 0)#"
APPLICATIONTIMEOUT="#CreateTimeSpan(0, 0, 30, 0)#"
CLIENTSTORAGE="Registry">
<!--- Set the default session state to false so by default,
users are NOT logged into the application --->
<CFLOCK SCOPE="Session" TYPE="Exclusive" TIMEOUT="10">
<CFIF NOT IsDefined("Session.LoggedIn"

<CFPARAM NAME="Session.LoggedIn" DEFAULT="False">
</CFIF>
</CFLOCK>
<!--- if the user isn't logged in or they aren't currently on the login
page, send them to the login page --->
<CFLOCK SCOPE="Session" TYPE="ReadOnly" TIMEOUT="10">
<CFIF Not FindNoCase("mainlogin.cfm", CGI.SCRIPT_NAME)AND Not FindNoCase("makeuser1.cfm", CGI.SCRIPT_NAME)>
<CFLOCATION URL="mainlogin.cfm" ADDTOKEN="No">
</CFIF>
</CFLOCK>
<!--- Reset the CFID and CFToken cookies to expire session and client
variables after the user's browser closes --->
<CFIF IsDefined("Cookie.CFID"


<CFCOOKIE NAME="CFID" VALUE="#Cookie.CFID#">
<CFCOOKIE NAME="CFToken" VALUE="#Cookie.CFToken#">
</CFIF>
<!--- check to see if the application has been initialized. If not,
set the necessary application variables and initialize the app
<CFLOCK SCOPE="Application" TYPE="Exclusive" TIMEOUT="10">
<CFIF NOT IsDefined('Application.Initialized')>
<CFSET Application.DSN = "chat1">
<CFSET Application.AdminEmail = "email@email.com">
<!--- Set the application.initialized variable to true so that this
block of code does not execute every time the Application.cfm
file is called --->
<CFSET Application.Initialized = TRUE>
</CFIF>
</CFLOCK>--->
<CFSETTING ENABLECFOUTPUTONLY="No">
here is the mainlogin.cfm code & form:
<cfif #parameterexists(client.user)# is "no">
<cfset client.user = "anonymous">
<cfset client.usercolor = "red">
</cfif>
<form action="makeuser1.cfm">
<font face="verdana, arial" size="2"><b>Your Current login is: </b></font>
<br><input type="text" name="user" size=25 value="<cfoutput>#client.user#</cfoutput>">
<select name="usercolor">
<option value="<cfoutput>#client.usercolor#</cfoutput>" selected>select color
<option value="black"> black
<option value="crimson"> scarlet
<option value="goldenrod"> gold
<option value="cornflowerblue"> blue
<option value="teal"> navy
<option value="deeppink"> pink
<option value="darkmagenta"> purple
<option value="limegreen"> green
<option value="darkgreen"> dark green
<option value="teal"> teal
</select></td></tr><td width="25%"> </td>
<td valign="top" nowrap> <font face="verdana, arial" size="2" color="aqua"><b>You
may change login above</b></font><br>
<font face = verdana, arial, size="2"> (one word, no spaces)</font>
<font face="verdana, arial" size="2"><b>or keep it.</b></font> <br>
</td>
<td valign="bottom" align="left">
<input type="submit" value="login" name="submit">
</td>
<td width="25%"> </td>
</tr></table></form>
here is the makeuser1.cfm code:
<!--- set Session.LoggedIn to True, logging the user in --->
<CFSET session.LoggedIn="TRUE">
<CFLOCK TIMEOUT="30" THROWONTIMEOUT="No" TYPE="EXCLUSIVE" SCOPE="SESSION">
<CFIF #IsDefined(user)#>
<CFSET client.user = #user#>
<CFSET client.usercolor = "#usercolor#">
</CFIF>
</CFLOCK>
<SCRIPT LANGUAGE="JavaScript">
<!--
location.replace("myapp.cfm"

//-->
</SCRIPT>
I hope someone will take pity and see if they can see what is wrong - I just cannot find it ~ Thanks, megan