This commit is contained in:
		| @@ -1,6 +1,9 @@ | ||||
| package de.jottyfan.camporganizer.module.registration; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Arrays; | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
|  | ||||
| import javax.ws.rs.core.Response; | ||||
| import javax.ws.rs.core.Response.Status; | ||||
| @@ -11,6 +14,7 @@ import org.jboss.resteasy.client.jaxrs.internal.ResteasyClientBuilderImpl; | ||||
| import org.keycloak.OAuth2Constants; | ||||
| import org.keycloak.admin.client.KeycloakBuilder; | ||||
| import org.keycloak.admin.client.resource.UsersResource; | ||||
| import org.keycloak.models.UserModel; | ||||
| import org.keycloak.representations.idm.CredentialRepresentation; | ||||
| import org.keycloak.representations.idm.UserRepresentation; | ||||
| import org.springframework.beans.factory.annotation.Value; | ||||
| @@ -91,6 +95,7 @@ public class KeycloakRepository { | ||||
| 		user.setLastName(surname); | ||||
| 		user.setEmail(email); | ||||
| 		user.setCredentials(Collections.singletonList(passwordCredentials)); | ||||
| 		user.setRequiredActions(Arrays.asList(UserModel.RequiredAction.VERIFY_EMAIL.toString())); | ||||
| 		user.setEnabled(true); | ||||
|  | ||||
| 		return user; | ||||
| @@ -144,14 +149,4 @@ public class KeycloakRepository { | ||||
| 		return getKeycloak(url, realm, admin, password, clientId).build().realm(realm).users(); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * send a verification link for newly registered users | ||||
| 	 * | ||||
| 	 * @param userId the ID of the user | ||||
| 	 */ | ||||
| 	public void sendVerificationLink(String userId) { | ||||
| 		getUsersResource(keycloakUrl, keycloakRealm, keycloakAdminName, keycloakAdminPassword, keycloakClientId).get(userId) | ||||
| 				.sendVerifyEmail(); | ||||
| 	} | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -37,7 +37,7 @@ public class RegistrationBean implements Serializable { | ||||
| 	private String zip; | ||||
| 	@NotBlank(message = "Bitte gib den Ort deines Wohnsitzes an.") | ||||
| 	private String city; | ||||
| 	@Email(message = "Bitte gib eine gültige E-Mail-Adresse an (oder gar keine).") | ||||
| 	@Email(message = "Bitte gib eine gültige E-Mail-Adresse an (oder gar keine, falls du dich ohne Login anmelden möchtest).") | ||||
| 	private String email; | ||||
| 	private String phone; | ||||
| 	private String comment; | ||||
|   | ||||
| @@ -46,13 +46,6 @@ public class RegistrationService { | ||||
| 		Boolean result = gateway.register(bean); | ||||
| 		if (result && bean.getRegisterInKeycloak()) { | ||||
| 			keycloak.register(bean.getForename(), bean.getSurname(), bean.getLogin(), bean.getPassword(), bean.getEmail()); | ||||
| 			if (bean.getEmail() != null && !bean.getEmail().isBlank()) { | ||||
| 				try { | ||||
| 					keycloak.sendVerificationLink(bean.getLogin()); | ||||
| 				} catch (Exception e) { | ||||
| 					LOGGER.error(e.getMessage(), e); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		return result; | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user