Skip to main content
Participant
December 3, 2011
質問

How to automatically login a user after the account is provisioned

  • December 3, 2011
  • 返信数 1.
  • 3036 ビュー

My application uses cflogin and a loginform.cfm as is often shown for authenticating the user.  I have a form where a new user can register and create an account.  After I create the account, I want the user to already be authenticated and able to use the application.  However, I can't find a way to get this to happen.  The new user is brought to the loginform and asked to enter the username and password.  How can I bypass this step?

このトピックへの返信は締め切られました。

返信数 1

BKBK
Community Expert
Community Expert
December 4, 2011

I'll assume you log users in using cflogin and cfloginuser.Then getAuthUser() will contain the user's username. If the user is not logged in, getAuthUser() will return an empty string.

You could therefore use getAuthUser() to prevent ColdFusion from sending a logged-in user to the login form. However, that isn't neat. It in fact suggests your design should be improved.

If you did indeed implement cflogin and cfloginuser the recommended way, then ColdFusion will bypass the cflogin tag when a user is logged in. To implement that part correctly, find the code that sends a user to the login form and place it within the context of the cflogin tag. Also, I would set the loginStorage attribute to "session". That will ensure that the login persists for the duration of the session, while the user navigates from one page to the next.

You did enforce login for a reason. So I'll assume that there are certain pages or parts of your application that you wish to expose only to users who have logged in. For those pages or parts, you could do something like

<cfif getAuthUser() is not "">

<!--- functionality to expose only to logged-in user --->

</cfif>

wilsonwf1作成者
Participant
December 13, 2011

The problem is that the user is not logged in because he's a new user.  getAuthUser returns an empty string.  The new user goes to a form to sign up for an account and enters new user name and password.  I save that in the database.  At this point the user is still NOT logged in but I have his username and password.

Now I could just take the new user to the login screen and have him reenter the username and password and he would be logged in.  But this seem like an extra step.  I want to call the cflogin functions and log the user in WITHOUT going to the login screen and WITHOUT him reentering his username and password.  I want to use the data that he used to create the account to log him in behind the scenes.  But I can figure out how to do that.

Inspiring
December 13, 2011

What type of authentication are you telling cflogin to use?  Are you authenticating against the Windows active directory (NTauthentication)?  When you talk about the login form popping up after the user is first setup, are you talking about the Windows domain login form or your own login form wanting to interact with the user to get his credentials?

-reed