I am attempting to make a login block function for my application. It is
using NT to authenticate the user using Active Directory. It authenticates
the user and logs them in, but I have no roles. What am I doing wrong or how
do I pass the roles back to the page so hey can be used? Thanks for any
help.
<cffunction name="authUser" access="public" returntype="string">
<cfargument name="username" type="string" required="yes">
<cfargument name="password" type="string" required="yes">
<cfset username=trim(arguments.username)>
<cfset password=trim(arguments.password)>
<cfset domain="avemaria" />
<cfset authenicated = authenticate(#username#, #password#,
#domain#)>
<cfif authenticated.auth eq "YES">
<cfset success = 1>
<cfset groups = #authenticated.groups#>
<cfset userCred = setUserCred(#username#, #password#, #groups#)>
<cfset setSessions = setSessions(#username#)>
<cfset result = "success">
<cfelse>
<cfset result = "failure">
<cfset success = 0>
</cfif>
<cfset userLog = logUser(#username#, #password#, #success#)>
<cfreturn result>
</cffunction>
<cffunction name="authenticate" access="private" output="false"
returntype="struct" hint="I authenticate against the NT server">
<cfargument name="username" type="string" required="yes">
<cfargument name="password" type="string" required="yes">
<cfargument name="domain" type="string" required="yes">
<cfntauthenticate username="#username#" password="#password#"
domain="#domain#" result="authenticated" listgroups="yes">
<cfreturn authenticated>
</cffunction>
<cffunction name="setUserCred" access="private" output="false"
returntype="void" hint="I set credentical to cfloginuser">
<cfargument name="username" type="string" required="yes">
<cfargument name="password" type="string" required="yes">
<cfargument name="group" type="string" required="yes">
<cfloginuser name="#username#" password="#password#"
roles="#groups#">
</cffunction>

Signature
Wally Kolcz
MyNextPet.org
Founder / Developer
586.871.4126
GArlington - 24 Sep 2007 10:29 GMT
> I am attempting to make a login block function for my application. It is
> using NT to authenticate the user using Active Directory. It authenticates
[quoted text clipped - 48 lines]
> Founder / Developer
> 586.871.4126
When calling functions like
<cfset authenicated = authenticate(#username#, #password#, #domain#)>
<cfset userCred = setUserCred(#username#, #password#, #groups#)>
<cfset setSessions = setSessions(#username#)>
<cfset userLog = logUser(#username#, #password#, #success#)>
DO NOT use values (#username# inserts a value of username into the
call), using username as in <cfset setSessions =
setSessions(username)> will use a variable when calling a function and
will pass a value or a reference depending on the data type. By using
variable names you will avoid problems like the one you have now, when
you use a value <cfset userCred = setUserCred(#username#, #password#,
#groups#)> CF will call the function with 'yourUserName_as1stParam',
'yourPassword_as2ndParam', yourGroupsCommaSeparatedPresumably -
effectively breaking your groups into 3rd, 4th and further parameters
in the call...