Problem with Pre Events, Login and Post Events

Riccardo Saponi, modified 7 Years ago. New Member Posts: 15 Join Date: 11/18/15 Recent Posts

Hi guys,

a strange problem in one of our Liferay 6.2 ga4.

We have a installation in a Centos Server, with a Liferay 6.2 ga4 and an integration with another user repository (external database).

We have made a Pre-Login Action and a Post-Login Action.

In the Pre-Login Action we read the external user repository and we create or update users in Liferay (with Groups and Roles associated).

In the Post-Login Action we do some operation fo the landing page.

In the Pre-Login Action we also set the Status of the User based on the external one. If we disable the external user, we set the status  WorkflowConstants.STATUS_INACTIVE in Liferay User, and when we re-enable this user we do the same in Liferay User. 

Now....

During the process of re-activation, we set the status with the UserLocalServiceUtil API ( updateStatus). We check the Liferay DB and we see the status updated.

But...

When this user login for the first time after the re-activation we have the Inactive Message  (see the attachment).

With a little debug we see that in Post Action the user have the old status (inactive). User is retrieved with PortalUtil.getUser(httpservletrequest).

I think that this is the User in Liferay Session.

So...in the Pre-Login we have the user's status with value WorkflowConstants.STATUS_APPROVED, and in the Post-Login we have the user's status with value  WorkflowConstants.STATUS_INACTIVE.

The next strange thing is that after a reload of the page the user is logged and active.

The Answer is: why during the login Liferay does not update the user in session? And why this happens only on the first attempt?

There is a way to avoid this behaviour?

We have already tried with some re-index operation but nothing change. Se the code below.

Indexer userIndexer = IndexerRegistryUtil.getIndexer(User.class.getName());<br> userIndexer.reindex(User.class.getName(), user.getUserId());

Thank you!

 

 

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
Riccardo Saponi:

With a little debug we see that in Post Action the user have the old status (inactive). User is retrieved with PortalUtil.getUser(httpservletrequest).

I think that this is the User in Liferay Session.

Close. If you look at the source code for PortalImpl.getUser(), you'll see that it's saved as an attribute on the request.

Riccardo Saponi:

The Answer is: why during the login Liferay does not update the user in session? And why this happens only on the first attempt?

There is a way to avoid this behaviour?

Sure, after you've updated the user, just replace the request attribute with your updated user. As for why Liferay doesn't do this for you automatically, it's probably because Liferay developers are human.