fixed registration bugs
This commit is contained in:
@@ -65,7 +65,7 @@ public class RegistrationController extends CommonController {
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
for (ObjectError error : bindingResult.getAllErrors()) {
|
||||
LOGGER.info("found {}", error);
|
||||
LOGGER.error("found {}", error);
|
||||
}
|
||||
CampBean campBean = service.getCamp(bean.getFkCamp());
|
||||
model.addAttribute("camp", campBean);
|
||||
@@ -79,7 +79,7 @@ public class RegistrationController extends CommonController {
|
||||
}
|
||||
Integer result = service.register(bean, getCurrentUser());
|
||||
if (result < 1) {
|
||||
LOGGER.trace("added less than 1 row");
|
||||
LOGGER.error("added less than 1 row on registering {}", bean);
|
||||
CampBean campBean = service.getCamp(bean.getFkCamp());
|
||||
model.addAttribute("camp", campBean);
|
||||
model.addAttribute("sexes", EnumConverter.getSexes());
|
||||
|
||||
@@ -119,6 +119,7 @@ public class RegistrationRepository {
|
||||
if (bean.getLogin() != null && !bean.getLogin().isEmpty()) {
|
||||
Boolean loginNotYetInUse = isLoginNotYetInUse(bean.getLogin().toLowerCase());
|
||||
if (bean.getRegisterInKeycloak() && !loginNotYetInUse) {
|
||||
LOGGER.error("login already in use: {}", bean.getLogin().toLowerCase());
|
||||
throw new DataAccessException("login already in use: " + bean.getLogin().toLowerCase());
|
||||
}
|
||||
Integer fkProfile = null;
|
||||
|
||||
@@ -24,7 +24,7 @@ import de.jottyfan.camporganizer.module.registration.validate.ValidUsername;
|
||||
@UnusedUsername(field = "login", message = "Dieses Login ist leider bereits vergeben. Bitte wähle ein anderes.")
|
||||
@TeacherAgeCheck(field = "birthDate", fkCamp = "fkCamp", campRole = "campRole", message = "Als Mitarbeiter bist Du leider zu jung für diese Freizeit.")
|
||||
@AlreadyRegisteredCheck(field = "forename", surname = "surname", birthDate = "birthDate", fkCamp = "fkCamp", message = "Diese Anmeldung wurde bereits vorgenommen. Wenn Du sie in Deinem Profil nicht sehen kannst, wurde sie vielleicht von jemand Anderem durchgeführt. In Absprache mit der Freizeitleitung kannst Du die Anmeldung von einem Administrator Deinem Konto zuordnen lassen.")
|
||||
@ValidUsername(field = "login", message = "Bitte überprüfe das Feld Login. Dort sind Leerzeichen nicht erlaubt.")
|
||||
@ValidUsername(field = "login", require = "registerInKeycloak", message = "Bitte überprüfe das Feld Login. Dort sind Leerzeichen nicht erlaubt.")
|
||||
public class RegistrationBean implements Serializable {
|
||||
//TODO: registration completeness annotation; in case of registerInKeycloak == true, force login, password, kcForename, kcSurname and kcEmail not to be blank
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
||||
@@ -22,6 +22,7 @@ public @interface ValidUsername {
|
||||
String message() default "username is invalid";
|
||||
|
||||
String field();
|
||||
String require();
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
|
||||
@@ -14,20 +14,28 @@ public class ValidUsernameValidator implements ConstraintValidator<ValidUsername
|
||||
|
||||
private String field;
|
||||
private String message;
|
||||
private String require;
|
||||
|
||||
public void initialize(ValidUsername vu) {
|
||||
this.field = vu.field();
|
||||
this.message = vu.message();
|
||||
this.require = vu.require();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Object value, ConstraintValidatorContext context) {
|
||||
Object login = new BeanWrapperImpl(value).getPropertyValue(field);
|
||||
String loginString = String.valueOf(login);
|
||||
Boolean result = login != null && !loginString.isBlank() && !loginString.contains(" ");
|
||||
if (!result) {
|
||||
context.buildConstraintViolationWithTemplate(message).addPropertyNode(field).addConstraintViolation()
|
||||
.disableDefaultConstraintViolation();
|
||||
Boolean forceCheck = (Boolean) new BeanWrapperImpl(value).getPropertyValue(require);
|
||||
Boolean result = null;
|
||||
if (forceCheck != null && forceCheck) {
|
||||
Object login = new BeanWrapperImpl(value).getPropertyValue(field);
|
||||
String loginString = String.valueOf(login);
|
||||
result = login != null && !loginString.isBlank() && !loginString.contains(" ");
|
||||
if (!result) {
|
||||
context.buildConstraintViolationWithTemplate(message).addPropertyNode(field).addConstraintViolation()
|
||||
.disableDefaultConstraintViolation();
|
||||
}
|
||||
} else {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user