Hi Seth. At first look that seems like it would work. I got a little
confused with you creating a variable called user but instantiating a CFC
called "login", but that would be easy enough to clarify.
When I've done this sort of thing, I've used the <cflogin> tag, which means
your LoginManager can check against getAuthUser() to determine if the
current user is logged in. That lets you eliminate some of that checking
from the UserLogin object.
As an aside, when you are reading from shared scope variables like the
session scope you don't need an exclusive lock. Exclusive locks are for
writing to the variable, readonly locks are for reading. In fact, as long as
you are diligent about exclusively locking all of your writes to shared
scopes, you don't even need to lock the reads.
Hope that helps,
Brian
On 6/24/05, Buntin, Seth - KATE <[EMAIL PROTECTED]> wrote:
>
> I am trying to visualize the Login Process for a CFC I am trying to
> create. I am new to the idea of "OOP" in CF and might need a big knock
> in the head once you see the problem.
>
>
>
> I want to manage all of the Users Information in the Session Scope so
> that I can access the information from any page and create a more
> complex set of user authorization.
>
>
>
> Here is what I have so far. I have taken the idea of this out of the
> fb41bookstore sample from Brian Kotek's website. His example is a
> shopping cart and mine is user login so that is one reason why I can't
> visualize this...
>
>
>
> (This application is in the ModelGlue framework)
>
> loginManager.cfc
>
>
>
> <cfcomponent displayname="Session Facade for User Login"
> hint="loginManager">
>
>
>
> <cffunction name="init" access="public"
> returntype="coe_worm.controller.loginController" output="false"
> hint="User Login Constructor.">
>
> <cfreturn this />
>
> </cffunction>
>
>
>
> <cffunction name="paramUser" access="public"
> returntype="void" output="false" hint="If session.user does not exist,
> create it.">
>
> <cfif not structKeyExists( session, 'user' )>
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfif not
> structKeyExists( session, 'user' )>
>
> <cfset
> session.user = createObject('component', 'coe_worm.model.login').init()
> />
>
> </cfif>
>
> </cflock>
>
> </cfif>
>
> </cffunction>
>
>
>
> <cffunction name="getUser" access="public"
> returntype="coe_worm.model.login" output="false" hint="Return the user
> object.">
>
> <cfset paramUser() />
>
> <cflock scope="session" timeout="10"
> type="readOnly">
>
> <cfreturn session.user />
>
> </cflock>
>
> </cffunction>
>
>
>
> <cffunction name="login" access="public"
> returntype="coe_worm.model.login" output="false" hint="Login">
>
> <cfargument name="username" required="true" />
>
> <cfargument name="password" required="true" />
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfset
> session.user.login(arguments.username, arguments.password) />
>
> </cflock>
>
>
>
> </cffunction>
>
>
>
> <cffunction name="setDisplayName" access="public"
> returntype="void" displayname="Set Display Name" output="false"
> hint="Set the display name of the user.">
>
> <cfargument name="displayname" type="string"
> required="yes" />
>
> <cfset paramUser() />
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfset
> session.user.setDisplayName(arguments.displayname) />
>
> </cflock>
>
> </cffunction>
>
>
>
> <cffunction name="setIsLoggedIn" access="public"
> returntype="void" displayname="Set Is Logged In" output="false"
> hint="Set the logged in status of the user.">
>
> <cfargument name="isLoggedIn" type="boolean"
> required="yes" />
>
> <cfset paramUser() />
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfset
> session.user.setIsLoggedIn(arguments.isLoggedIn) />
>
> </cflock>
>
> </cffunction>
>
>
>
> <cffunction name="setUserGroups" access="public"
> returntype="void" displayname="Set User Groups" output="false" hint="Set
> the user groups of the user.">
>
> <cfargument name="userGroups" type="string"
> required="yes" />
>
> <cfset paramUser() />
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfset
> session.user.setUserGroups(arguments.userGroups) />
>
> </cflock>
>
> </cffunction>
>
>
>
> <cffunction name="getDisplayName" output="false" hint="Get
> the user's display name.">
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfset userDisplayName =
> session.user.getDisplayName() />
>
> </cflock>
>
>
>
> <cfreturn userDisplayName />
>
> </cffunction>
>
>
>
> <cffunction name="getIsLoggedIn" output="false" hint="Get
> the variable to see if the user is logged in.">
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfset IsLoggedIn =
> session.user.getIsLoggedIn() />
>
> </cflock>
>
>
>
> <cfreturn IsLoggedIn />
>
> </cffunction>
>
>
>
> <cffunction name="getUserGroups" output="false" hint="Get
> the user's groups.">
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfset userGroups =
> session.user.getUserGroups() />
>
> </cflock>
>
>
>
> <cfreturn userGroups />
>
> </cffunction>
>
>
>
> </cfcomponent>
>
>
>
> Login.cfc:
>
> <cfcomponent displayname="User Login" hint="User Login Component">
>
> <cffunction name="init" returntype="coe_worm.model.login"
> output="false">
>
> <cfparam name="variables.user"
> default="#structNew()#" />
>
> <cfreturn this />
>
> </cffunction>
>
>
>
> <cffunction name="getUser" access="public"
> returntype="coe_worm.model.login" output="false" hint="Return the user
> object.">
>
> <cfreturn this />
>
> </cffunction>
>
>
>
> <cffunction name="login" output="false">
>
> <cfargument name="username" type="string"
> required="true" />
>
> <cfargument name="password" type="string"
> required="true" />
>
>
>
> <cftry>
>
> <cfset iamgood = "yes">
>
> <cfset longUserName =
> arguments.username & "***">
>
> <cfset myfilter =
> "userPrincipalName=" & longUserName>
>
> <cfldap ...>
>
> <cfcatch type="any">
>
> <cfset iamgood = "no">
>
> </cfcatch>
>
> </cftry>
>
>
>
> <cfif iamgood eq "yes">
>
> <cfset LoggedIn = true>
>
> <cfoutput query="getinfo">
>
> <cfset UserGroups = "">
>
> <cfloop index="myx"
> from="1" to="#listlen(memberof)#">
>
> <cfif
> trim(listgetat(listgetat(memberof,myx),1,"=")) eq "CN">
>
>
> <cfset UserGroups = UserGroups &
> listgetat(listgetat(memberof,myx),2,"=") & ",">
>
> </cfif>
>
> </cfloop>
>
> <cfset UserGroups =
> mid(usergroups, 1, len(usergroups)-1)>
>
> <cfset fname =
> givenname>
>
> <cfset lname = sn>
>
> <cfset displayname =
> getinfo.displayname>
>
> </cfoutput>
>
> <cfelse>
>
> <cfset LoggedIn = false>
>
> <cfset UserGroups = "">
>
> <cfset displayname = "">
>
> </cfif>
>
>
>
> <cfset LogIn = StructNew()>
>
> <cfset LogIn.LoggedIn = #LoggedIn#>
>
> <cfset LogIn.UserGroups = #UserGroups#>
>
> <cfset LogIn.displayname = #displayname#>
>
>
>
> <cfreturn LogIn>
>
> </cffunction>
>
>
>
> <cffunction name="setUserGroups" output="false" hint="Set
> the user's groups.">
>
> <cfargument name="value" type="string"
> required="true">
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfset session.user.UserGroups =
> arguments.value>
>
> </cflock>
>
> </cffunction>
>
>
>
> <cffunction name="setIsLoggedIn" output="false" hint="Set
> the variable to see if the user is logged in.">
>
> <cfargument name="value" type="boolean"
> required="true">
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfset session.user.IsLoggedIn =
> arguments.value>
>
> </cflock>
>
> </cffunction>
>
>
>
> <cffunction name="setDisplayName" output="false" hint="Set
> the user's display name.">
>
> <cfargument name="value" type="string"
> required="true">
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfset session.user.DisplayName =
> arguments.value>
>
> </cflock>
>
> </cffunction>
>
>
>
> <cffunction name="getUserGroups" output="false" hint="Get
> the user's groups.">
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfreturn session.user.UserGroups>
>
> </cflock>
>
> </cffunction>
>
>
>
> <cffunction name="getIsLoggedIn" output="false" hint="Get
> the variable to see if the user is logged in.">
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfreturn session.user.IsLoggedIn>
>
> </cflock>
>
> </cffunction>
>
>
>
> <cffunction name="getDisplayName" output="false" hint="Get
> the user's display name.">
>
> <cflock scope="session" timeout="10"
> type="exclusive">
>
> <cfreturn session.user.DisplayName>
>
> </cflock>
>
> </cffunction>
>
>
>
> </cfcomponent>
>
>
>
> What am I missing? Or am I doing this correctly?
>
>
>
> Thanks,
>
> Seth
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking
application. Start tracking and documenting hours spent on a project or with a
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:210536
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54