Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing password reminder (security-questions)

I have customized sign-up page using a hook.

I want to add the security question in the sign up page where as the default security question is set when user logs-in Liferay the first time.

So how can I add security question in the sign-up page instead on first time login?

like image 893
nebula Avatar asked Nov 12 '22 13:11

nebula


1 Answers

Firstly, you have to customize the create_account.jsp page, adding the same select boxes and inputs normally found on update_reminder_query.jsp: that is, you have to add the UI for entering the password reminder while creating the account.

After that, you have to save those values for the new User, and you can probably hook the UserLocalService implementation, adding the code to update the reminder query. A thing like this should work:

public class UserLocalServiceImpl extends UserLocalServiceWrapper {

  public UserLocalServiceImpl(UserLocalService userLocalService) {
    super(userLocalService);
  }

  @Override
  public User addUser(
      long creatorUserId, long companyId, boolean autoPassword,
      String password1, String password2, boolean autoScreenName,
      String screenName, String emailAddress, long facebookId, 
      String openId, Locale locale, String firstName, String middleName, 
      String lastName, int prefixId, int suffixId, boolean male, 
      int birthdayMonth, int birthdayDay, int birthdayYear, 
      String jobTitle, long[] groupIds, long[] organizationIds, 
      long[] roleIds, long[] userGroupIds, boolean sendEmail, 
      ServiceContext serviceContext)
    throws PortalException, SystemException {

    // User

    User user = super.addUser(
      creatorUserId, companyId, autoPassword, password1, password2,
      autoScreenName, screenName, emailAddress, facebookId, openId, 
      locale, firstName, middleName, lastName, prefixId, suffixId, male, 
      birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, 
      organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

    // Reminder query

    String question = ParamUtil.getString(
      serviceContext, "reminderQueryQuestion");
    String answer = ParamUtil.getString(
      serviceContext, "reminderQueryAnswer");

    if (Validator.isNotNull(question) || Validator.isNotNull(answer)) {
      if (question.equals(UsersAdminUtil.CUSTOM_QUESTION)) {
        question = ParamUtil.getString(
          serviceContext, "reminderQueryCustomQuestion");
      }

      updateReminderQuery(user.getUserId(), question, answer);
    }

    return user;
  }

}

You could override the CreateAccount Struts actions, but I think it's safer to do this thing in the service, in order to be transactional in case of errors (for example, if the User does not enter an answer for the reminder query)... but you should check it to be sure!

Also, you'll probably have to customize the Struts action anyway, in order to deal with a possible UserReminderQueryException...

like image 103
Andrea Di Giorgi Avatar answered Dec 21 '22 17:12

Andrea Di Giorgi