Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
lou cat
account created by user/admin in onAfterCreate
November 5, 2012 4:18 AM
Answer

lou cat

Rank: Regular Member

Posts: 196

Join Date: January 26, 2012

Recent Posts

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!
David H Nebinger
RE: account created by user/admin in onAfterCreate
November 5, 2012 6:11 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7157

Join Date: September 1, 2006

Recent Posts

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.
lou cat
RE: account created by user/admin in onAfterCreate
November 6, 2012 8:14 AM
Answer

lou cat

Rank: Regular Member

Posts: 196

Join Date: January 26, 2012

Recent Posts

thank you David, I'll let you know if that works
lou cat
RE: account created by user/admin in onAfterCreate
February 5, 2013 7:48 AM
Answer

lou cat

Rank: Regular Member

Posts: 196

Join Date: January 26, 2012

Recent Posts

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!!