Pregunta

I'm trying to add some validation steps to the user registration process in Liferay, but can't seem to find the right place to do so.

As far as I know, there's no event where I could add my own code when creating a new user (contrary to the login process where we have the "login.events.post" event).

Is there any way to do this?

UPDATE: we're trying to avoid redoing what liferay already does, even if creating a new user registration portlet makes a lot of sense.

I just found out about the "servlet.service.events.pre" event and thought that a hook could be created on the CreateAccountAction class to add my own validation, but I'm not getting much from liferay's documentation on this topic. Any ideas/suggestions/links would be greatly appreciated.

¿Fue útil?

Solución 2

Ended up creating a hook on create_account.jsp and used ajax to do some validations (together with server-side validation) on the new user's info. Then created another hook on login.jsp (which is executed right after liferay finishes creating the new user account).

When login.jsp is loaded, liferay evaluates if a user was added before landing on this page:

<c:if test='<%= SessionMessages.contains(request, "user_added") %>'>

It's right there where we added a second round of our own validations on the newly created user.

Otros consejos

Am trying to suggest a very simple way below.

You don't have to create a hook to override the existing Liferay's User Registration form. You can create your own customized User Registration form with your favourite view technology and with your own customized fields (I mean, less number of fields compared to Liferay's User Registration fields). All validations on this form will be done by your code and error messages will be thrown by your code only. Only when all of the validations pass through, you can call Liferay's addUser method.

Am just trying to provide an example below. Modify the code as per your requirement.

if(allValidationsPassThrough)
{
 long[] organizationIds = { 111L }; //Just an example. Check the Organisation ID you are using
long[] groupIds = { 222L };
long[] roleIds = { 333L };
long[] userGroupIds = (long[])null;
String screenName = yourBean.getUser(); //Just an example

UserLocalServiceUtil.addUser(//Pass the parameters to this method );
}

Note : There are many parameters that this method expects. In User Registration form, if you are not capturing Birthday (for eg.,) , then pass the value as null or your own birthday :)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top