As Dave said cflogin does a lot of things other than just setting session
variables.  But whatever works, I found that using the cflogin in MX was
much easier than writing my own, especially if you want to do several
things during login.  Basically what I did was the following:

In my Application.cfm page I have the following lines:

<CFIF GetFileFromPath(GetBaseTemplatePath()) NEQ "Login.cfm">
         <CFINCLUDE TEMPLATE="/MyEU/Login.cfm">
</CFIF>

Login.cfm is the following:

<!---
  Page:           Login.cfm
  Function:       Processes a users login to the MyEU site.
  Created by: Bill Grover
--->
<cfif NOT IsDefined("SESSION.nUserID")>
         <cflogout>
</cfif>

<cflogin>
         <cfif IsDefined("FORM.UserName") AND IsDefined("FORM.UserPass")>
                 <cfstoredproc procedure="rGetUserInfo"
                           datasource="#APPLICATION.cWebClientDSN#"
                           username="#APPLICATION.cWebClientUser#"
                           password="#APPLICATION.cWebClientPass#">
                         <cfprocparam type="In"
                                      cfsqltype="CF_SQL_VARCHAR"
                                      value="#FORM.UserName#"
                                  null="No">
                         <cfprocparam type="In"
                                      cfsqltype="CF_SQL_VARCHAR"
                                      value="#FORM.UserPass#"
                                  null="No">
                         <cfprocresult name="WebClientInfo">
                 </cfstoredproc>

                 <cfif WebClientInfo.RecordCount EQ 1>
                         <cfloginuser name="#WebClientInfo.wcu_userid#"
                                      password="#FORM.UserPass#"
                                      roles="">
                         <cfset SESSION.nUserID          =
WebClientInfo.wcu_id>
                         <cfset SESSION.cUserName        =
WebClientInfo.wcu_userid>
                         <cfset SESSION.cUserPass        = FORM.UserPass>
                         <cfset SESSION.cUserFullName= WebClientInfo.wcu_name>
                         <cfset SESSION.cEMail           =
WebClientInfo.wcu_email>
                         <cfset SESSION.cCompanyName =
WebClientInfo.wcu_company>
                         <cfset SESSION.lUserMaint       =
WebClientInfo.wcu_usermaint>
                 </cfif>

                 <cfset llJustLoggedIn = "Yes">
         </cfif>
</cflogin>

<cfif GetAuthUser() EQ "">
         <cfif GetFileFromPath(GetBaseTemplatePath()) NEQ "GetLogin.cfm">
                 <cfinclude template="GetLogin.cfm">
         </cfif>
         <cfabort>
</cfif>

And GetLogin.cfm is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!---
  Page:           GetLogin.cfm
  Function:       Prompts for a user's login to the MyEU site.
  Created by: Bill Grover
--->

<cfoutput>
<html>
<head>
         <title>
                 #APPLICATION.cTitle#
         </title>
</head>

<body>
         <cfinclude template="header.cfm">

         <cfif ListFindNoCase(APPLICATION.cLoginPageList,
GetFileFromPath(GetBaseTemplatePath()))>
                 <form action="">                        method="post">
         <cfelse>
                 <cfset lcDestination = Trim(CGI.path_info)>
                 <cfif CGI.query_string NEQ "">
                          <cfset lcDestination = lcDestination & "?" &
CGI.query_string>
                 </cfif>
                 <form action="">                        method="post">

                         <cfloop collection="#form#" item="lcField">
                                 <cfif ListFindNoCase("UserName,UserPass",
lcField) EQ 0>
                                         <input type="Hidden"
name="#lcField#" value="#Form[lcField]#">
                                 </cfif>
                         </cfloop>
         </cfif>

         <div class="normal bold">
                 Welcome to myEU. Log in here to access your FTP and/or
online inventory site if you already have a username and password assigned.
         </div>
         <P>
         <table>
                 <tr>
                         <td>User:</td>
                         <td>
                                 <input type="text"
                                        name="UserName"
                                        size="15"
                                        maxlength="15">
                         </td>
                 </tr>
                 <tr>
                         <td>Password:</td>
                         <td>
                                 <input type="password"
                                        name="UserPass"
                                        size="15"
                                        maxlength="15">
                         </td>
                 </tr>
                 <tr>
                         <td align="center" colspan="2">
                                 <input type="submit"
                                        value="Login">
                                 <input type="reset"
                                        value="Reset">
                         </td>
                 </tr>
         </table>

         </form>

         <P>

         <div class="normal">
                 If you do not have a username and password, or this is
your first time
                 to myEU, you may request a username and
password
                 <cfswitch _expression_="#UCase(CGI.SERVER_NAME)#">
                         <cfcase value="EU-2000-MIS">
                                 <a href="">                          </cfcase>
                         <cfcase value="LOCALHOST">
                                 <a href="">                          </cfcase>
                         <cfdefaultcase>
                                 <a href="">                          </cfdefaultcase>
                 </cfswitch>
                 <P>Your request will be handled promptly. Note: you must
be an EU Services' customer to request a myEU username and password
                 <P>Note to Mac users: We recommend you use Fetch for your
FTP client. Internet Explorer will not work as an FTP client on a Mac platform.
         </div>

         <P>

         <cfinclude template="Footer.cfm">
</body>
</html>
</cfoutput>

At 10:53 AM 12/30/2003 -0800, you wrote:
>Dave,
>I appreciate your (always thoughtful) response. I was hoping to
>take advantage of cflogin since moving to CFMX, but in this
>particular case, I think I'm trying to fit a square peg into a
>round hole. I'll probably continue to roll my own until I'm in a
>situation where cflogin is a better fit.
>
>Dave Jones
>NetEffect
>
>At 11:18 AM 12/30/03 -0500, you wrote:
> > > So then my question is, why do I need cflogin? cfloginuser used
> > > by itself will log in a user. GetAuthUser will test if a user
> > > is logged in.
> >
> >The CFLOGIN tag does quite a bit more than just ask whether the user has
> >logged in. It allows you access to the CFLOGIN structure (useful if you're
> >using web server authentication, or follow the standard "j_username" and
> >"j_password" naming scheme for HTML login forms). It lets you specify the
> >length of a login period. It lets you control the scope of login cookies
> >sent to the client.
> >
> > > Yes I've read the CF docs and see their example of using cflogin
> > > and cfloginuse. But, a) I don't like loading up my application.cfm
> > > with a lot of code, and b) I'm using Mach-II and want to test for
> > > user authentication in a preEvent plugin, not in application.cfm.
> >
> >I don't see how you'll have any less code if you test whether a user is
> >logged in by using GetAuthUser(). In any case, you typically don't need a
> >lot of code for a login process. You don't have to put it in
> >Application.cfm, you just need to ensure that it's used on every page where
> >you want the user logged in before they can see the page. Usually, the
> >easiest way to do this is to use Application.cfm, of course.
> >
> >Dave Watts, CTO, Fig Leaf Software
> ><http://www.figleaf.com/>http://www.figleaf.com/
> >voice: (202) 797-5496
> >fax: (202) 797-5444
> >
> >----------
> >[
>
>----------
>[
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to