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

UserRoles and CF Script Problem

New Here ,
Feb 11, 2009 Feb 11, 2009
Hi,

I am trying to create a way for only "administrators" to download an application. I'm not getting any errors but I'm not getting the result I expected. I want it to see that if you're logged in as "admin" you get a link that says "download". If not, you get some other text. This is what I have:



<!-- COLDFUSION login_action.cfm --->

<cfif Len(trim(Username)) IS 0>
<font face="Arial, Helvetica, sans-serif" size="-1" color="#990000" >
Error: Username is required.
<cfabort></cfif>

<cfif Len(trim(userpassword)) is 0>
<font face="Arial, Helvetica, sans-serif" size="-1" color="#990000">Error: Password is required.
<cfabort>
</cfif>


<cfquery datasource="myDS" name="qryLogin">
SELECT username, userpassword, userrole
FROM userinfo
WHERE username = '#form.username#' and userpassword= '#form.userpassword#'
</cfquery>

<cfif qryLogin.recordCount gt 0>
<font face="Arial, Helvetica, sans-serif" size="-1">Login successful. Welcome <cfoutput>
#username#. </cfoutput>

<cfset SESSION.isLoggedIn ="yes">
<cflogin>
<cfif IsDefined ( "cflogin" ) >
<cfif cflogin.username eq "#qryLogin.username#" and "#qryLogin.userrole#" eq "0">
<cfset roles="administrator">
<cfelse>
<cfset roles="user">
</cfif>


<cfloginuser name = "#cflogin.username#"
password="#cflogin.userpassword#"
roles="#roles#" >
</cfif></cflogin>

<cfscript>
if (IsUserInRole("0"))
WriteOutput("you're admin!<br>");
if (IsUserInRole("1"))
WriteOutput("foo");

</cfscript>

<cfelse>

<font face="Arial, Helvetica, sans-serif" size="-1" color="#990000">That record does not exist. Please try again.
<cfinclude template="login_form.cfm">
<cfabort></cfif>

<cfif not isDefined ("SESSION.isLoggedIn")>
Please log in.<cfabort></cfif>



If anyone can give me some illumination on why it's not seeing the userroles, I would be very appreciative. Also, there are nine user roles and one one can download the application. Would it make more sense in the CFScript to say

If 0, you're admin and get download link
if else, you get plain text.

?

Thanks for your help!

519
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 ,
Feb 11, 2009 Feb 11, 2009
Does this mean the person is an administrator?
"#qryLogin.userrole#" eq "0"
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
New Here ,
Feb 11, 2009 Feb 11, 2009
Yes, that is what it is supposed to mean.
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 ,
Feb 11, 2009 Feb 11, 2009
I generally troubleshoot if/else logic like this.

<cfif something>
true
<cfelse>
false
<cfdump something>
</cfif>
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
New Here ,
Feb 11, 2009 Feb 11, 2009
It's not working. It just spits out the same user role and name no matter what I do. Is the "eq 0" okay?
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 ,
Feb 11, 2009 Feb 11, 2009
LATEST
is it the number 0 or the string "0"?
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