0

I am having some issues with the OOTB SiteRegistrationController and corresponding page. It works fine unless I try to register a new user with the same Username. In this case it errors with Your request cannot be processed at this time. This site administrator has been alerted.

It does not email the admin on the company profile page(me). I have been unable to get the debug logs to trace this class. So I have been running it anonymously to try and figure out what is going on and why it does not handle this situation. This seems like it should be OOTB functionality, which makes me feel like I am missing something.

I have found this issue on ideas. Yet it has more comments than it does votes(1).

1
  • Just something I came across that will be available for use in Spring '16 release. System.Site.isValidUsername(username); Jan 12 '16 at 14:43
0

That default registration controller is garbage, and it doesn't actually contain anything to check and see if the email address is already registered. You'll need to add in some validation code to query the user object with the input username to see if you return an existing user prior to attempting to create the new user. See an example of this below where i query for users that have the profile assigned to my community with the entered username. If i return a value, i set valid to false and return a page message that tells the user the username is already taken.

List<User> existingUsers = [select Id from user where username = :username AND ProfileId = '00e330000014Itc'];
  if (existingUsers.size() > 0) {
      addErrorMessage('That email address has already been registered.');
      valid = false;
  }

And then wrap that user creation chunk of code in an if statement that depends on the valid variable being true so you dont try and create a user with a duplicate username.

if(valid == true){
String userId = Site.createPortalUser(u, accountId, password);
if (userId != null) { 
    if (password != null && password.length() > 1) {
        return Site.login(username, password, null);
    }
    else {
        PageReference page = System.Page.SiteRegisterConfirm;
        page.setRedirect(true);
        return page;
    }
}}

This should hopefully set you in the right direction. Let me know if you need more help or a better explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.