CF - If statement not reacting to session role

I am trying to have one of two include files used by the program based on the session user role.  The if statement is

<cfif isDefined("SESSION.Role")eq 0>
<cfinclude template="sidebar_menuUser.cfm">
<cfelse>
<cfinclude template="sidebar_menuAdmin.cfm">
</cfif>

The problem is users are seeing the admin menu sidebar.

Any help is appreciated
JohnMac328Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Andrew MaurerConnect With a Mentor Commented:
Im not exactly sure how your login sctructure is setup. Can you do

<dump var="#session#">

above this line..

<cfif isDefined("SESSION.Role") AND SESSION.Role EQ 0 >

Roles could be a list..
0
 
Andrew MaurerCommented:
try
<cfif isDefined("SESSION.Role")>
<cfinclude template="sidebar_menuUser.cfm">
<cfelse>
<cfinclude template="sidebar_menuAdmin.cfm">
</cfif>

OR if you mean it is not defined

<cfif NOT isDefined("SESSION.Role")>
<cfinclude template="sidebar_menuUser.cfm">
<cfelse>
<cfinclude template="sidebar_menuAdmin.cfm">
</cfif>

Open in new window

0
 
JohnMac328Author Commented:
There is a role defined which is either a value of 0 which is user or 1 which is Admin.  Here is what is at the top of the login page, does a part of this also need to be in every page?

<CFIF CHECK_USER.RECORDCOUNT GT 0>
  <CFSET SESSION.LoggedIn="Yes">
  <CFSET SESSION.EmployeeID=CHECK_USER.EmployeeID>
  <CFSET SESSION.Role=CHECK_USER.role>
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Andrew MaurerCommented:
then..
<cfif isDefined("SESSION.Role") AND SESSION.Role EQ 0 >
<cfinclude template="sidebar_menuUser.cfm">
<cfelse>
<cfinclude template="sidebar_menuAdmin.cfm">
</cfif>

Open in new window

0
 
Andrew MaurerCommented:
Im not sure if you need it on every page.. if you did, I would say you'd want it in app cfc or app cfm
0
 
JohnMac328Author Commented:
Still not working, here is what is in the application.cfm, the employee table has a 'role' field with either 0 or 1, is check_user a CF defined term?  I am updating a program written by someone else.
<cfif structKeyExists(form,"Password")>
   
    <cfquery name="check_user" datasource="#datasource#">
           SELECT EmployeeID, Role FROM Employees
 WHERE Email = '#Form.Email#'
 AND Password = '#Form.Password#'
    </cfquery>

    <!-- <cfif check_user.recordcount is not 0>
        <!-- Log them in with a timeout of 30 minutes (1800 sec) and set level of Admin-->
        <cflogin idletimeout="1800">
            <cfloginuser 
                    name = "#FORM.Email#"
                    password ="#FORM.Password#"
                    roles = "#check_user.Role#">
        </cflogin>
    <cfelse>
        <!-- If an invalid Login Attemp, Set invalid to 1 for invalid login script -->
        <cfset invalid_login = 1>
    </cfif>
</cfif>

Open in new window

0
 
JohnMac328Author Commented:
It saw my role as being 1 which is correct, and saw the user as 0 which is correct.  For some reason the if statement is not being observed.

employeeid 231  
loggedin Yes  
role 1  
sessionid f030fca1e861ef4f9f511953372375b1f692  
urltoken CFID=8400&CFTOKEN=89814093&jsessionid=f030fca1e861ef4f9f511953372375b1f692
0
 
Andrew MaurerCommented:
curious... Unix box?

another way tot test is put a dump in each of the  if sections


<cfif isDefined("session.role") AND session.role EQ 0 >
<cfinclude template="sidebar_menuUser.cfm">
<cfelse>
<cfinclude template="sidebar_menuAdmin.cfm">
</cfif>

TEST 
<cfif isDefined("session.role") AND session.role EQ 0 >
ROLE EQ 0<BR/>
<cfelse>
ROLE EQ ELSE<BR/>
</cfif>

Open in new window

0
 
JohnMac328Author Commented:
Forgot to transfer this to the other pages, seems to work fine now.

Thanks for your help
0
All Courses

From novice to tech pro — start learning today.