Foros de discusión

account created by user/admin in onAfterCreate

thumbnail
lou cat, modificado hace 11 años.

account created by user/admin in onAfterCreate

Regular Member Mensajes: 196 Fecha de incorporación: 26/01/12 Mensajes recientes
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, modificado hace 11 años.

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

Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
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, modificado hace 11 años.

RE: account created by user/admin in onAfterCreate

Regular Member Mensajes: 196 Fecha de incorporación: 26/01/12 Mensajes recientes
thank you David, I'll let you know if that works
thumbnail
lou cat, modificado hace 11 años.

RE: account created by user/admin in onAfterCreate

Regular Member Mensajes: 196 Fecha de incorporación: 26/01/12 Mensajes recientes
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!!