Foren

account created by user/admin in onAfterCreate

thumbnail
lou cat, geändert vor 11 Jahren.

account created by user/admin in onAfterCreate

Regular Member Beiträge: 196 Beitrittsdatum: 26.01.12 Neueste Beiträge
Hi!

I created a hook to have an email notification every time a new account is created, it was quite easy extendind BaseModelListener<User> and overriding onAfterCreate.

Is there a way, from that method, to differentiate a user creation done by the user herself from the creation done by some other portal user/admin?

In fact I only need the mail if the user creates his/her own account...

I hope this can be done just extending that method, if you have in mind any attribute that can distinguish the two kind of new users, let me know emoticon

thanks!
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: account created by user/admin in onAfterCreate (Antwort)

Liferay Legend Beiträge: 14915 Beitrittsdatum: 02.09.06 Neueste Beiträge
There is nothing in the User object itself to determine who is creating the record.

That said, you may be able to get to one of the ThreadLocal variables to see who the user is that's logged in and determine if they are an administrator or not.

For example, you can use PrincipalThreadLocal.getName() to possibly get the user id (note this is normally a long for the user id, not actually a name) of the current user.
thumbnail
lou cat, geändert vor 11 Jahren.

RE: account created by user/admin in onAfterCreate

Regular Member Beiträge: 196 Beitrittsdatum: 26.01.12 Neueste Beiträge
thank you David, I'll let you know if that works
thumbnail
lou cat, geändert vor 11 Jahren.

RE: account created by user/admin in onAfterCreate

Regular Member Beiträge: 196 Beitrittsdatum: 26.01.12 Neueste Beiträge
it worked David!

using PrincipalThreadLocal.getName() inside the afterCreate method, I can get the userId of who is creating that account, and if the account is created by a stranger, it would be just a "null" value.

thanks!!