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

Checking session variables

Contributor ,
May 27, 2014 May 27, 2014

I have an external login service that I'm using to authenticate users.  After logging in, I get an XML file from which I can pull things like user ID and rights.

The login page redirects to an index page in another folder (which is protected by the authentication service) and on that page, I have a <cfif> statement that looks at rights.

The rights returned are "J" (for judge) and "A" (for admin), which I'm setting as the session variable: session.rights

If I do this:

<cfif session.rights eq "A">

admin section

<cfelseif session.rights eq "J">

judge section

<cfelse>

redirect to the login page

</cfif>

The else is what triggers.  If I cfoutput #session.rights# I get J, but for some reason, J does not equal J.  I've tried trimming it and everything, to no avail.

Any ideas?

690
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

correct answers 1 Correct answer

Engaged , May 28, 2014 May 28, 2014

there's your problem.  Session.rights does not = "J", it's a block of XML.  You'd need to at least say

<cfelseif session.rights.XmlText eq "J"> 

Translate
Engaged ,
May 28, 2014 May 28, 2014

could it be possible that session.rights has some whitespace around it e.g. "  J" or "J  " ?  When you output it you'll only see 'J' but session.rights EQ "J" == false.  You may just need to trim it:

<cfelseif trim(session.rights) eq "J">

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
Enthusiast ,
May 28, 2014 May 28, 2014

Please do a <CFDUMP VAR="#session#"> and paste the results here. Try an IS as opposed to EQ as well, to see if that helps.

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
Contributor ,
May 28, 2014 May 28, 2014

Yeah, I've trimmed everything everywhere, to no avail.

Here's the dump result:

struct
emailaddr [empty string]
newitem 1
rights
xml element
XmlNameTPEA_USER_TYPE
XmlNsPrefix
XmlNsURI
XmlTextJ
XmlComment
XmlAttributes
struct [empty]
XmlChildren 
sessionid f0306d37e90bce8a818d7d7843e36516f1e7
tpeauser <?xml version="1.0" encoding="UTF-8"?> <NAME_FIRST>Dave</NAME_FIRST> <?xml version="1.0" encoding="UTF-8"?> <NAME_LAST>Johnson</NAME_LAST>
trackingno 0
upacsid [empty string]
upacsserver [empty string]
urltoken  CFID=26143&CFTOKEN=6071485a4b7e13-F5282421-A324-841F-59919221D2C51604&jsessionid=f0306d37e90bce8a818d7d7843e36516f1e7 
userid
xml element
XmlNameUSER_ID
XmlNsPrefix
XmlNsURI
XmlText25481
XmlComment
XmlAttributes
struct [empty]
XmlChildren 
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
Engaged ,
May 28, 2014 May 28, 2014

there's your problem.  Session.rights does not = "J", it's a block of XML.  You'd need to at least say

<cfelseif session.rights.XmlText eq "J"> 

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
Enthusiast ,
May 28, 2014 May 28, 2014

Good job I asked for a CFDUMP lol

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
Contributor ,
May 28, 2014 May 28, 2014

tribule wrote:

Good job I asked for a CFDUMP lol

Yes!  That was helpful, but it appears we can no longer mark posts as helpful.

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
Adobe Employee ,
May 28, 2014 May 28, 2014

Go to "Actions" and select "Mark as Helpful".

BreakawayPaul wrote:

Yes!  That was helpful, but it appears we can no longer mark posts as helpful.

Regards,

Anit Kumar

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
Contributor ,
May 28, 2014 May 28, 2014

Anit Kumar Panda wrote:

Go to "Actions" and select "Mark as Helpful".

My only option there is to "Report Abuse".

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
Contributor ,
May 28, 2014 May 28, 2014

bingo duncan!

Weird, I was setting that variable like this:

<cfset upacscreds = XMLParse(upacsauth)>

<cfset session.rights = upacscreds.user.row[1].tpea_user_type>

What's the proper way to set it so that I don't have to append .XmlText onto everything?

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
Engaged ,
May 28, 2014 May 28, 2014

I'd simply do

<cfset session.rights = upacscreds.user.row[1].tpea_user_type.XMLText>

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
Contributor ,
May 28, 2014 May 28, 2014
LATEST

duncancumming wrote:

I'd simply do

<cfset session.rights = upacscreds.user.row[1].tpea_user_type.XMLText>

Yep, I had *just* figured that out.  It was too obvious, which is why it eluded me.

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