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!