Forums de discussion

account created by user/admin in onAfterCreate

thumbnail
lou cat, modifié il y a 11 années.

account created by user/admin in onAfterCreate

Regular Member Publications: 196 Date d'inscription: 26/01/12 Publications récentes
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, modifié il y a 11 années.

RE: account created by user/admin in onAfterCreate (Réponse)

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
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, modifié il y a 11 années.

RE: account created by user/admin in onAfterCreate

Regular Member Publications: 196 Date d'inscription: 26/01/12 Publications récentes
thank you David, I'll let you know if that works
thumbnail
lou cat, modifié il y a 11 années.

RE: account created by user/admin in onAfterCreate

Regular Member Publications: 196 Date d'inscription: 26/01/12 Publications récentes
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!!