61 MultivaluedMap<String, String> formData = context.getHttpRequest().getDecodedFormParameters();
62 List<FormMessage> errors =
new ArrayList<>();
64 context.getEvent().detail(Details.REGISTER_METHOD,
"form");
65 String eventError = Errors.INVALID_REGISTRATION;
67 if (Validation.isBlank(formData.getFirst((RegistrationPage.FIELD_FIRST_NAME)))) {
68 errors.add(
new FormMessage(RegistrationPage.FIELD_FIRST_NAME, Messages.MISSING_FIRST_NAME));
71 if (Validation.isBlank(formData.getFirst((RegistrationPage.FIELD_LAST_NAME)))) {
72 errors.add(
new FormMessage(RegistrationPage.FIELD_LAST_NAME, Messages.MISSING_LAST_NAME));
75 String email = formData.getFirst(Validation.FIELD_EMAIL);
76 boolean emailValid =
true;
77 if (Validation.isBlank(email)) {
78 errors.add(
new FormMessage(RegistrationPage.FIELD_EMAIL, Messages.MISSING_EMAIL));
80 }
else if (!Validation.isEmailValid(email)) {
81 context.getEvent().detail(Details.EMAIL, email);
82 errors.add(
new FormMessage(RegistrationPage.FIELD_EMAIL, Messages.INVALID_EMAIL));
86 if (emailValid && !context.getRealm().isDuplicateEmailsAllowed() && context.getSession().users().getUserByEmail(email, context.getRealm()) != null) {
87 eventError = Errors.EMAIL_IN_USE;
88 formData.remove(Validation.FIELD_EMAIL);
89 context.getEvent().detail(Details.EMAIL, email);
90 errors.add(
new FormMessage(RegistrationPage.FIELD_EMAIL, Messages.EMAIL_EXISTS));
93 if (errors.size() > 0) {
94 context.error(eventError);
95 context.validationError(formData, errors);