掲示板

Creating new users and logging them in

thumbnail
11年前 に Dave Weitzel によって更新されました。

Creating new users and logging them in

Regular Member 投稿: 208 参加年月日: 09/11/18 最新の投稿
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 ?
11年前 に Siby Mathew によって更新されました。

RE: Creating new users and logging them in

Expert 投稿: 268 参加年月日: 11/03/04 最新の投稿
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
thumbnail
11年前 に Apoorva Prakash によって更新されました。

RE: Creating new users and logging them in

Liferay Master 投稿: 658 参加年月日: 10/06/15 最新の投稿
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:
LoginUtil.login(request, response, loginUser, password, false, CompanyConstants.AUTH_TYPE_EA)


HTH...

Thanks and Regards,
Apoorva Prakash
thumbnail
11年前 に Dave Weitzel によって更新されました。

RE: Creating new users and logging them in

Regular Member 投稿: 208 参加年月日: 09/11/18 最新の投稿
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 :

[indent]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.[/indent]

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:
LoginUtil.login(request, response, loginUser, password, false, CompanyConstants.AUTH_TYPE_EA)


HTH...

Thanks and Regards,
Apoorva Prakash
thumbnail
11年前 に Hitoshi Ozawa によって更新されました。

RE: Creating new users and logging them in

Liferay Legend 投稿: 7942 参加年月日: 10/03/24 最新の投稿
Instead of a portlet, why don't you just write an ext plugin and make it part of Liferay Control Panel feature?
thumbnail
11年前 に Apoorva Prakash によって更新されました。

RE: Creating new users and logging them in

Liferay Master 投稿: 658 参加年月日: 10/06/15 最新の投稿
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?

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

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

HTH...

Thanks and Regards,
Apoorva Prakash
thumbnail
11年前 に Dave Weitzel によって更新されました。

RE: Creating new users and logging them in

Regular Member 投稿: 208 参加年月日: 09/11/18 最新の投稿
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?
thumbnail
11年前 に Dave Weitzel によって更新されました。

RE: Creating new users and logging them in (回答)

Regular Member 投稿: 208 参加年月日: 09/11/18 最新の投稿
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).