return RegistrationForm.class.isAssignableFrom(aClass);
}
@Override
public void validate(Object o, Errors errors) {
RegistrationForm registrationForm = (RegistrationForm) o;
checkForInvitations(registrationForm.getEmail(), errors);
if (registrationForm.getFirstName() == null || "".equals(registrationForm.getFirstName().trim())) {
registrationForm.setFirstName(null);
errors.rejectValue(FIRST_NAME_FIELD, "registrationValidator.emptyFirstName");
}
if (registrationForm.getLastName() == null || "".equals(registrationForm.getLastName().trim())) {
registrationForm.setLastName(null);
errors.rejectValue(LAST_NAME_FIELD, "registrationValidator.emptyLastName");
}
if (registrationForm.getEmail() == null || "".equals(registrationForm.getEmail().trim())) {
registrationForm.setEmail(null);
errors.rejectValue(EMAIL_FIELD, "registrationValidator.email.invalid");
} else {
Pattern pattern = Pattern.compile(emailPattern);
Matcher m = pattern.matcher(registrationForm.getEmail());
if (!m.matches()) {
errors.rejectValue(EMAIL_FIELD, "registrationValidator.email.invalid");
} else if (userService.getByEmail(registrationForm.getEmail()) != null) {
errors.rejectValue(EMAIL_FIELD, "registrationValidator.emailAlreadyExists");
}
}
if (!isPasswordValid(registrationForm.getFirstPassword())) {
errors.rejectValue(FIRST_PASSWORD_FIELD, "registrationValidator.password.invalid");
}
if (!doPasswordsMatch(registrationForm.getFirstPassword(), registrationForm.getSecondPassword())) {
errors.rejectValue(FIRST_PASSWORD_FIELD, "registrationValidator.passwordMismatch");
}
}