Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Dave Weitzel
Creating new users and logging them in
March 12, 2013 9:23 AM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 186

Join Date: November 18, 2009

Recent Posts

I am trying to write a new "join this web site" portlet that will create new Liferay users and log then in as part of a user dialogue that will ultimately take them to the check out to collect some dues.
I don't seem to be able get the system to log them in after they have filled in an initial page of name email address etc (like the create account page).
I have tried setting session attributes.
I have tried setting cookies - even the ones used by RememberMe login.
nothing seems to last the duration of the portlet when it renders page 2 of the application.
I have written my own AutoLogin hook but that isnt the right approach as the user needs to be logged in before the portlet renders page 2 and it woudl rely on cookies or session attributes which arent there.

I have had to clone a lot of code that seems to only be in the portal-impl.jar as well. (addCookie(), LoginUtll.login()) which may be a reason why I cannt get any firther.

I must be missing something very simple that I cannot find in the documentation.

How do you tell Liferay that this user (the one I have just created ) is the authenticated user for this session ?
Siby Mathew
RE: Creating new users and logging them in
March 20, 2013 6:29 AM
Answer

Siby Mathew

Rank: Expert

Posts: 261

Join Date: March 4, 2011

Recent Posts

Hi Dave,
I have found a similar issue : http://www.liferay.com/community/forums/-/message_boards/message/13721047

You can check the classes mentioned in the answer. Maybe this can help you.

Thanks,
Siby
Apoorva Prakash
RE: Creating new users and logging them in
March 20, 2013 6:59 AM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

Dave Weitzel:
I am trying to write a new "join this web site" portlet that will create new Liferay users and log then in as part of a user dialogue that will ultimately take them to the check out to collect some dues.
I don't seem to be able get the system to log them in after they have filled in an initial page of name email address etc (like the create account page).
I have tried setting session attributes.
I have tried setting cookies - even the ones used by RememberMe login.
nothing seems to last the duration of the portlet when it renders page 2 of the application.
I have written my own AutoLogin hook but that isnt the right approach as the user needs to be logged in before the portlet renders page 2 and it woudl rely on cookies or session attributes which arent there.

I have had to clone a lot of code that seems to only be in the portal-impl.jar as well. (addCookie(), LoginUtll.login()) which may be a reason why I cannt get any firther.

I must be missing something very simple that I cannot find in the documentation.

How do you tell Liferay that this user (the one I have just created ) is the authenticated user for this session ?


Hello Dave,

Auto login hook automatically logs User after registration. You just have to make available the contents of credentials array.

If you are trying to log in using custom code, you can use the following, it works with charm:
1LoginUtil.login(request, response, loginUser, password, false, CompanyConstants.AUTH_TYPE_EA)


HTH...

Thanks and Regards,
Apoorva Prakash
Dave Weitzel
RE: Creating new users and logging them in
March 20, 2013 8:00 PM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 186

Join Date: November 18, 2009

Recent Posts

Thanks for the suggestions,
The issue with LoginUtil.login is that it isn't available to us as it is part of portal-impl

can you explain how you can access that class or which part is vital to the process that we can use?

I have been trying to basically clone its code but setting cookies doesn't seem to work from within the portlet context and I still have a suspicion it is the cookies that make the login work, as I cannot see what within the LoginUtil.login() code will tell LIferay this user is now authrticated.

The auto Login code I have tried doesn't seem to work but I cannot see why not however like so many elements in the Documentation it is good but not quite complete.
from what I can tell the credentials have to be :

String.valueOf(userId) (eg 12301)
String value of user password UNENCODED (as if typed by user into login form)
Boolean.FALSE.toString() - not sure what this is for but suspect it is to do with doActionAfterLogin which in itself isn't really explained anywhere.

I also found you cannot put your own AutoLogin hook as well as the others without getting deployment errors (But I think they do all get called).
Can you confirm the credentials are as above?

Dave
Apoorva Prakash:


Hello Dave,

Auto login hook automatically logs User after registration. You just have to make available the contents of credentials array.

If you are trying to log in using custom code, you can use the following, it works with charm:
1LoginUtil.login(request, response, loginUser, password, false, CompanyConstants.AUTH_TYPE_EA)


HTH...

Thanks and Regards,
Apoorva Prakash
Hitoshi Ozawa
RE: Creating new users and logging them in
March 20, 2013 8:35 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

Instead of a portlet, why don't you just write an ext plugin and make it part of Liferay Control Panel feature?
Apoorva Prakash
RE: Creating new users and logging them in
March 20, 2013 9:29 PM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

Dave Weitzel:

The issue with LoginUtil.login is that it isn't available to us as it is part of portal-impl

can you explain how you can access that class or which part is vital to the process that we can use?

I've used it in EXT-plugin, and it works fine in EXT.

Dave Weitzel:

Can you confirm the credentials are as above?

1String[] credentials = null;
2credentials[0] = << UserId >>;
3credentials[1] = << Password >>;
4credentials[2] = << Remember Me >>;

However I suggest you to have a look on com.liferay.portal.security.auth.RememberMeAutoLogin

HTH...

Thanks and Regards,
Apoorva Prakash
Dave Weitzel
RE: Creating new users and logging them in
March 21, 2013 11:17 AM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 186

Join Date: November 18, 2009

Recent Posts

Thanks for feedback
but I am not sure how I would be using an ext environment here. I have included a version of LoginUtil() in my own portlet (MyLoginUtil with any reference to constants etc in impl converted to strings and a few unnecessary sections removed (like killing concurrent sessions)

Are you saying put the LoginUtil class in an ext environment, how would I still call it from within my main portlet that is processing an application to join the site?

ext I thought was to change the behavior of Liferay code (or fix bugs).

I have code that adds a user to the system and ten turns of the password reset and reminder questions.
At that point before they are returned to fill in page 2 of the application I want to log them in.
I tried calling MyLoginUtil.login() which returned an Authenticate.SUCCESS but would not set the cookies and the user isnt logged in despite having supposedly been authenticated

So I am still none the wiser as to what actually has to happen for a session to be authenticated and a user deemed to be logged in as far as all the user interfaces are concerned.

If you have used it in an ext plugin can you explain what you put in the ext plug in and how you were referencing that code from elsewhere?
Dave Weitzel
RE: Creating new users and logging them in
March 27, 2013 2:02 PM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 186

Join Date: November 18, 2009

Recent Posts

Just to let you all know that I have managed to do this now and it may have been done earlier but I didn't know it.

Currently I still use my own local version of LoginUtil.login() I call MyLoginUtil.login() rather than use an ext non-change.

The added magic is that you have to do a sendRedirect at the end so the system (themeDisplay at least) will see you are logged in and the landing page will act accordingly. If you just let the standard render phase take over the theme doesnt know you are logged in.

This system still isn't setting any cookies for RememberMeAutoLogin but is sufficent for my need as users need to go through payment and other things before we lwt them log in for themselves.

Thanks for help
(See new post about ExpandoAttributes though).