register from dashboard (background functionality)
This commit is contained in:
parent
f13a645549
commit
3e1e5e12ab
@ -48,7 +48,7 @@ public class RegistrationController extends CommonController {
|
||||
model.addAttribute("camp", campBean);
|
||||
return "/registration/registration";
|
||||
}
|
||||
Boolean result = service.register(bean);
|
||||
Boolean result = service.register(bean, getCurrentUser(request));
|
||||
return result ? "/registration/success" : "/error";
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ import org.jooq.DeleteConditionStep;
|
||||
import org.jooq.InsertResultStep;
|
||||
import org.jooq.InsertValuesStep12;
|
||||
import org.jooq.InsertValuesStep13;
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.Record7;
|
||||
import org.jooq.SelectConditionStep;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
@ -76,7 +77,7 @@ public class RegistrationGateway {
|
||||
* @param login the login
|
||||
* @return true or false
|
||||
*/
|
||||
public Boolean isLoginAvailable(String login) {
|
||||
public Boolean isLoginNotYetInUse(String login) {
|
||||
SelectConditionStep<TProfileRecord> sql = jooq
|
||||
// @formatter:off
|
||||
.selectFrom(T_PROFILE)
|
||||
@ -96,48 +97,61 @@ public class RegistrationGateway {
|
||||
public Boolean register(RegistrationBean bean) {
|
||||
LambdaResultWrapper lrw = new LambdaResultWrapper();
|
||||
jooq.transaction(t -> {
|
||||
if (bean.getRegisterInKeycloak()) {
|
||||
if (!isLoginAvailable(bean.getLogin())) {
|
||||
if (bean.getLogin() != null && !bean.getLogin().isEmpty()) {
|
||||
Boolean loginNotYetInUse = isLoginNotYetInUse(bean.getLogin());
|
||||
if (bean.getRegisterInKeycloak() && !loginNotYetInUse) {
|
||||
throw new DataAccessException("login already in use: " + bean.getLogin());
|
||||
}
|
||||
// TODO: check if teacher is at least 2 years older than the camp participants
|
||||
String oldPassword = new StrongPasswordEncryptor().encryptPassword(bean.getPassword());
|
||||
InsertResultStep<TProfileRecord> sql1 = DSL.using(t)
|
||||
// @formatter:off
|
||||
.insertInto(T_PROFILE,
|
||||
T_PROFILE.FORENAME,
|
||||
T_PROFILE.SURNAME,
|
||||
T_PROFILE.USERNAME,
|
||||
T_PROFILE.PASSWORD,
|
||||
T_PROFILE.DUEDATE,
|
||||
T_PROFILE.UUID)
|
||||
.values(bean.getForename(), bean.getSurname(), bean.getLogin(), oldPassword, LocalDateTime.now().plus(356, ChronoUnit.DAYS), UUID.nameUUIDFromBytes(bean.getLogin().getBytes()).toString())
|
||||
.returning(T_PROFILE.PK);
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql1.toString());
|
||||
Integer fkProfile = sql1.fetchOne().getPk();
|
||||
Integer fkProfile = null;
|
||||
if (loginNotYetInUse) {
|
||||
String oldPassword = new StrongPasswordEncryptor().encryptPassword(bean.getPassword());
|
||||
InsertResultStep<TProfileRecord> sql1 = DSL.using(t)
|
||||
// @formatter:off
|
||||
.insertInto(T_PROFILE,
|
||||
T_PROFILE.FORENAME,
|
||||
T_PROFILE.SURNAME,
|
||||
T_PROFILE.USERNAME,
|
||||
T_PROFILE.PASSWORD,
|
||||
T_PROFILE.DUEDATE,
|
||||
T_PROFILE.UUID)
|
||||
.values(bean.getForename(), bean.getSurname(), bean.getLogin(), oldPassword, LocalDateTime.now().plus(356, ChronoUnit.DAYS), UUID.nameUUIDFromBytes(bean.getLogin().getBytes()).toString())
|
||||
.returning(T_PROFILE.PK);
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql1.toString());
|
||||
fkProfile = sql1.fetchOne().getPk();
|
||||
} else {
|
||||
SelectConditionStep<Record1<Integer>> sql1 = DSL.using(t)
|
||||
// @formatter:off
|
||||
.select(T_PROFILE.PK)
|
||||
.from(T_PROFILE)
|
||||
.where(T_PROFILE.USERNAME.eq(bean.getLogin()));
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql1.toString());
|
||||
fkProfile = sql1.fetchOne().get(T_PROFILE.PK);
|
||||
}
|
||||
// register the person for camp participation
|
||||
InsertValuesStep13<TPersonRecord, String, String, EnumSex, LocalDate, String, String, String, String, String, EnumCamprole, Integer, String, Integer> sql2 = DSL
|
||||
.using(t)
|
||||
// @formatter:off
|
||||
.insertInto(T_PERSON,
|
||||
T_PERSON.FORENAME,
|
||||
T_PERSON.SURNAME,
|
||||
T_PERSON.SEX,
|
||||
T_PERSON.BIRTHDATE,
|
||||
T_PERSON.STREET,
|
||||
T_PERSON.ZIP,
|
||||
T_PERSON.CITY,
|
||||
T_PERSON.EMAIL,
|
||||
T_PERSON.PHONE,
|
||||
T_PERSON.CAMPROLE,
|
||||
T_PERSON.FK_CAMP,
|
||||
T_PERSON.COMMENT,
|
||||
T_PERSON.FK_PROFILE)
|
||||
.values(bean.getForename(), bean.getSurname(), bean.getSex(),
|
||||
bean.getBirthDate(), bean.getStreet(), bean.getZip(), bean.getCity(), bean.getEmail(),
|
||||
bean.getPhone(), bean.getCampRole(), bean.getFkCamp(), bean.getComment(), fkProfile);
|
||||
// @formatter:on
|
||||
// @formatter:off
|
||||
.insertInto(T_PERSON,
|
||||
T_PERSON.FORENAME,
|
||||
T_PERSON.SURNAME,
|
||||
T_PERSON.SEX,
|
||||
T_PERSON.BIRTHDATE,
|
||||
T_PERSON.STREET,
|
||||
T_PERSON.ZIP,
|
||||
T_PERSON.CITY,
|
||||
T_PERSON.EMAIL,
|
||||
T_PERSON.PHONE,
|
||||
T_PERSON.CAMPROLE,
|
||||
T_PERSON.FK_CAMP,
|
||||
T_PERSON.COMMENT,
|
||||
T_PERSON.FK_PROFILE)
|
||||
.values(bean.getForename(), bean.getSurname(), bean.getSex(),
|
||||
bean.getBirthDate(), bean.getStreet(), bean.getZip(), bean.getCity(), bean.getEmail(),
|
||||
bean.getPhone(), bean.getCampRole(), bean.getFkCamp(), bean.getComment(), fkProfile);
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql2.toString());
|
||||
lrw.add(sql2.execute());
|
||||
// register the login for the portal
|
||||
|
@ -38,7 +38,11 @@ public class RegistrationService {
|
||||
* @param bean the bean
|
||||
* @return true if successful, false otherwise
|
||||
*/
|
||||
public Boolean register(RegistrationBean bean) {
|
||||
public Boolean register(RegistrationBean bean, String currentUser) {
|
||||
if (currentUser != null) {
|
||||
bean.setRegisterInKeycloak(false); // already registered
|
||||
bean.setLogin(currentUser);
|
||||
}
|
||||
Boolean result = gateway.register(bean);
|
||||
if (result && bean.getRegisterInKeycloak()) {
|
||||
keycloak.register(bean.getForename(), bean.getSurname(), bean.getLogin(), bean.getPassword(), bean.getEmail());
|
||||
|
@ -29,7 +29,7 @@ public class UnusedUsernameValidator implements ConstraintValidator<UnusedUserna
|
||||
@Override
|
||||
public boolean isValid(Object value, ConstraintValidatorContext context) {
|
||||
Object login = new BeanWrapperImpl(value).getPropertyValue(field);
|
||||
Boolean result = gateway.isLoginAvailable((String) login);
|
||||
Boolean result = gateway.isLoginNotYetInUse((String) login);
|
||||
if (!result) {
|
||||
context.buildConstraintViolationWithTemplate(message).addPropertyNode(field).addConstraintViolation()
|
||||
.disableDefaultConstraintViolation();
|
||||
|
@ -86,7 +86,7 @@
|
||||
<textarea class="form-control" placeholder="Sonstiges" th:field="*{comment}"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="row" th:if="${#strings.isEmpty(currentUser)}">
|
||||
<div class="col-sm-12 rowdist">
|
||||
<div class="form-check" title="Die Anmeldedaten können in den Kontoeinstellungen bearbeitet und für die nächsten Freizeitanmeldungen verwendet werden.">
|
||||
<input id="save" type="checkbox" class="form-check-input" th:field="*{registerInKeycloak}" onchange="$('#createlogin').toggle();" /> <label class="form-check-label" for="save">Anmeldedaten
|
||||
@ -94,7 +94,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="createlogin" class="row">
|
||||
<div id="createlogin" class="row" th:if="${#strings.isEmpty(currentUser)}">
|
||||
<div class="col-sm-6 rowdist">
|
||||
<span class="error" th:each="error : ${#fields.errors('login')}">[[${error}]]<br /></span>
|
||||
<input type="text" placeholder="Login" th:field="*{login}" th:class="${#fields.hasErrors('login') ? 'inputerror' : 'form-control'}" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user