65 MultivaluedMap<String, String> formData = context.getHttpRequest().getDecodedFormParameters();
66 List<FormMessage> errors =
new ArrayList<>();
67 context.getEvent().detail(Details.REGISTER_METHOD,
"form");
69 String email = formData.getFirst(Validation.FIELD_EMAIL);
70 String username = formData.getFirst(RegistrationPage.FIELD_USERNAME);
71 context.getEvent().detail(Details.USERNAME, username);
72 context.getEvent().detail(Details.EMAIL, email);
74 String usernameField = RegistrationPage.FIELD_USERNAME;
75 if (context.getRealm().isRegistrationEmailAsUsername()) {
76 context.getEvent().detail(Details.USERNAME, email);
78 if (Validation.isBlank(email)) {
79 errors.add(
new FormMessage(RegistrationPage.FIELD_EMAIL, Messages.MISSING_EMAIL));
80 }
else if (!Validation.isEmailValid(email)) {
81 errors.add(
new FormMessage(RegistrationPage.FIELD_EMAIL, Messages.INVALID_EMAIL));
82 formData.remove(Validation.FIELD_EMAIL);
84 if (errors.size() > 0) {
85 context.error(Errors.INVALID_REGISTRATION);
86 context.validationError(formData, errors);
89 if (email != null && !context.getRealm().isDuplicateEmailsAllowed() && context.getSession().users().getUserByEmail(email, context.getRealm()) != null) {
90 context.error(Errors.EMAIL_IN_USE);
91 formData.remove(Validation.FIELD_EMAIL);
92 errors.add(
new FormMessage(RegistrationPage.FIELD_EMAIL, Messages.EMAIL_EXISTS));
93 context.validationError(formData, errors);
97 if (Validation.isBlank(username)) {
98 context.error(Errors.INVALID_REGISTRATION);
99 errors.add(
new FormMessage(RegistrationPage.FIELD_USERNAME, Messages.MISSING_USERNAME));
100 context.validationError(formData, errors);
104 if (context.getSession().users().getUserByUsername(username, context.getRealm()) != null) {
105 context.error(Errors.USERNAME_IN_USE);
106 errors.add(
new FormMessage(usernameField, Messages.USERNAME_EXISTS));
107 formData.remove(Validation.FIELD_USERNAME);
108 context.validationError(formData, errors);