Examples (iOS)
Examples (Android)

 

» Sign Up Assistant | Error messages

The Sign Up Assistant component provides several customizable error messages for all kinds of problems that may occur during the registration, activation or password recovery process.

The following is a list of all error codes available and their relative default messages:

SignUpErrorCodes enum Default message
MISSING_USERNAMEUser name is required
USERNAME_TOO_SHORT User name is too short, min amount of characters is %s
USERNAME_TOO_LONG User name is too long, max amount of characters is %s
USERNAME_ALREADY_IN_USEUsername: %s is already in use
MISSING_PASSWORDPassword is required
PASSWORD_TOO_SHORTPassword is too short, min. amount of characters is %s
PASSWORD_TOO_LONGPassword is too long, max. amount of characters is %s
MISSING_EMAILAn email is required
INVALID_EMAILEmail address: %s is invalid
EMAIL_ALREADY_IN_USEEmail address: %s is already in use
RECOVER_NO_USERPassword recovery error, username %s was not found
ACTIVATION_NO_IDInvalid Activation. Session doesn't contain a database ID
ACTIVATION_INVALID_CODEInvalid Activation Code received
GENERIC_DB_ERRORUnexpected Database Error. Please contact our support
CUSTOM_ERROR%s

All these error messages can be customized provided that placeholders are maintained in the same number in which they appear in the default values.

For example let's say we want to customize the INVALID_EMAIL message:

private void initSignUpAssistant()
{
	suac = new SignUpAssistantComponent();
    
    //...
	
    suac.getConfig().errorMessages.put(SignUpErrorCodes.INVALID_EMAIL, "%s doesn't look like a valid email address. Please provide one.");
}

It doesn't matter the position in which the placeholder is moved, as long as they are preserved within the string.

» Custom validation errors

The SignUpErrorCodes.CUSTOM_ERROR is a special code that can be used for custom validation purposes. We have seen in the first chapter that custom validation classes can be plugged into the Sign Up Assistant to check for extra fields. Let's go back to that example and review how an custom error can be thrown to interrupt the process and notify a problem to the client:

@Override
public void init()
{
	suac = new SignUpAssistantComponent();
	suac.getConfig().extraFields = Arrays.asList("country", "age");
	
	// Set limits for min/max name and password length
	suac.getConfig().minUserNameLength = 4;
	suac.getConfig().maxUserNameLength = 30;
	suac.getConfig().minPasswordLength = 8;
	suac.getConfig().maxPasswordLength = 30;
	
	// Add a pre-process plugin for custom validation
	suac.getConfig().preProcessPlugin = new ISignUpAssistantPlugin()
	{
		@Override
		public void execute(User user, ISFSObject params, SignUpConfiguration config) throws SignUpValidationException
		{
			Integer age = params.getInt("age");
		    String country = params.getUtfString("country");

		    if (age == null)
		    	throw new SignUpValidationException(SignUpErrorCodes.CUSTOM_ERROR, "The age is missing");
		
			if (age < 14)
		    	throw new SignUpValidationException(SignUpErrorCodes.CUSTOM_ERROR, "You must be at least 14 years old to access this game");
			

		    if (country == null || country.length() < 2)
		    	throw new SignUpValidationException(SignUpErrorCodes.CUSTOM_ERROR, "Pleas specify your country");
		}
	};
	
	
	addRequestHandler(SignUpAssistantComponent.COMMAND_PREFIX, suac);
}

» Wrapping up

This article completes the overview of the Sign Up Assistant component. It's time now to take a look at a practical example of it works. You can go back to index of this tutorial and take a look at the tutorial for Flash/ActionScript3 or iOS/Objective-C code.