Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Application log In

Guest
Mar 30, 2009 Mar 30, 2009
Why does the attached code not cause people to redirect to the login.cfm page if there is no accessAllowed session variable? If they log in and are successfull it sets the variable accessAllowed = true which means the user is authenticated however it stopped working and the only thing I can see that's changed is this code.
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 30, 2009 Mar 30, 2009
This is obviously in the application.cfc?

well, instead of using <cflocation> you could simply set request.targetpage to the login.cfm ...

Let me know if it works

Martin
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 30, 2009 Mar 30, 2009
try this:

<cfif (NOT structKeyExists(session,'accessAllowed')) OR
session.accessAllowed IS false>

you may also need a <cfabort> after your <cflocation> tag to prevent
processing of originally requested page...

also, onRequestStart() method should accept one argument - targetpage.

try this for a full code:

<cffunction name="onRequestStart" access="public" returntype="boolean"
output="true">
<cfargument name="TargetPage" type="string" required="yes" />
<!--- check to see if logged in --->
<cfif (NOT structKeyExists(session,'accessAllowed')) OR
session.accessAllowed IS false>
<!--- if not logged in and not on login page, redirect to login --->
<cfif listLast(cgi.script_name,'/') neq 'login.cfm'>
<cflocation url="login.cfm">
<cfabort>
<!--- you can also use <cfset getPageContext().forward('login.cfm')>
instead of above 2 lines --->
</cfif>
</cfif>
<cfreturn true>
</cffunction>



Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 30, 2009 Mar 30, 2009
I have this to process a log out how else could I do it?

<cfif structKeyExists(url,'clear')><cfset onApplicationStart()></cfif>
<cfif structKeyExists(url,'clear')><cfset structClear(session)></cfif>
</cffunction>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 30, 2009 Mar 30, 2009
you mean you are restarting your whole application (well,
re0initializing really) every time a user logs out???

but, really, if it is just a user logging out, why would you want to
call onApplicationStart()???

how else to do it would depend, to start with, on how you log your users
in...


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 30, 2009 Mar 30, 2009
Azadi your log in code worked once then it didn't

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 30, 2009 Mar 30, 2009
that would be because session.allowAccess exists and is true.

where exactly do you have this line:
<cfif structKeyExists(url,'clear')><cfset structClear(session)></cfif>
?

instead of posting snippets from different parts of your onRequestStart
method, why don;t you post all of it? the order you have various <cfif>
clauses inside of it may be very important...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 30, 2009 Mar 30, 2009
<cffunction name="onRequestStart" access="public" returntype="boolean"
output="true">
<cfargument name="TargetPage" type="string" required="yes" />
<!--- check to see if logged in --->
<cfif (NOT structKeyExists(session,'accessAllowed')) OR
session.accessAllowed IS false>
<!--- if not logged in and not on login page, redirect to login --->
<cfif listLast(cgi.script_name,'/') neq 'login.cfm'>
<cflocation url="login.cfm">
<!--- <cfabort>
you can also use <cfset getPageContext().forward('login.cfm')>
instead of above 2 lines --->
</cfif>
</cfif>
<cfreturn true>

<cfif structKeyExists(url,'clear')><cfset onApplicationStart()></cfif>
<cfif structKeyExists(url,'clear')><cfset structClear(session)></cfif>
</cffunction>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 30, 2009 Mar 30, 2009
try this code:

<cffunction name="onRequestStart" access="public" returntype="boolean"
output="true">
<cfargument name="TargetPage" type="string" required="yes" />
<cfset var qsStruct = oRequest.getParameterMap()>
<cfif structKeyExists(qsStruct,'clear')>
<cfset structClear(session)>
<cfset onApplicationStart()>
</cfif>
<!--- check to see if logged in --->
<cfif (NOT structKeyExists(session,'accessAllowed')) OR
session.accessAllowed IS false>
<!--- if not logged in and not on login page, redirect to login --->
<cfif listLast(cgi.script_name,'/') neq 'login.cfm'>
<cflocation url="login.cfm" addtoken="no">
<cfabort>
</cfif>
</cfif>
<cfreturn true>
</cffunction>


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 31, 2009 Mar 31, 2009
Azadi:

Received Variable oRequest is undefined error.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 31, 2009 Mar 31, 2009
sorry, my fault - bad copy/paste...

change this line:

<cfset var qsStruct = oRequest.getParameterMap()>

to:

<cfset var qsStruct = getPageContext().getRequest().getParameterMap()>

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 31, 2009 Mar 31, 2009
ok that works only if I log in then put ?clear=1 at the end of the url so how can we set it up to start out working?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 31, 2009 Mar 31, 2009
> so how can we set it up to start out working

?? what do you mean? lost...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 31, 2009 Mar 31, 2009
Meaning if you try and access the directory for the first time it doesn't work but if you log in then log out by hitting clear it forces you to go to the login screen which is what we want. So my question is what do I need to modify in the code so that we can have it start working on that first access?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 31, 2009 Mar 31, 2009
still not clear, sorry...

what do you mean by 'if you try and access the directory for the first
time it doesn't work'?

what does not work? how do you expect it to work? how is the way it
works different from what you expect?

what do you expect to happen when one accesses your directory for the
first time? what actually happens?

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 31, 2009 Mar 31, 2009
ok if you try to access any page inside the "Application" then you can get to it and are not redirected to the login page. However if you log in log out by using clear=1 in the url and then try and go back in and access another page without logging in the logic then forces you to go to the login page before trying to access any other page.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 31, 2009 Mar 31, 2009
ok, that's better.

now, where do you set the session.accessAllowed variable? post the code
that sets it.

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 31, 2009 Mar 31, 2009
<cfoutput query="Getlisting">

<CFIF Getlisting.recordcount EQ 1>
<cfset Session.accessAllowed = true>
<cfset Session.name = '#user_fname#'>
<cfset Session.role = '#user_role#'>
<CFLOCATION URL="index.cfm">
<CFELSE>
<cfset Session.accessAllowed = false>
<CFLOCATION URL="login.cfm?login=failed">
</CFIF>
</cfoutput>
<cfelse>
<cfoutput>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 31, 2009 Mar 31, 2009
LATEST
that should work ok...

just to rule out other possible issues, do this:

in your onSessionStart method in Application.cfc add
<cfset session.accessAllowed = false>

then clear the cach and cookies and authenticated sessions in your
browser and close it.

if you have another browser installed - strat that one and try accessing
your secured directory. ( if you do not have another browser insatlled -
shame on you as a web developer! 🙂 you can start the same browser
again, but better after the session timeout period only...)


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources