feat: send mail at account creation
This commit is contained in:
parent
bd757fc731
commit
cdca5c1aab
@ -47,13 +47,15 @@ public class KeycloakService {
|
||||
if (club.getClubId() == null) {
|
||||
LOGGER.infof("Creation of club group %d-%s...", club.getId(), club.getName());
|
||||
return vertx.getOrCreateContext().executeBlocking(() -> {
|
||||
GroupRepresentation clubGroup = keycloak.realm(realm).groups().groups().stream().filter(g -> g.getName().equals("club"))
|
||||
GroupRepresentation clubGroup =
|
||||
keycloak.realm(realm).groups().groups().stream().filter(g -> g.getName().equals("club"))
|
||||
.findAny().orElseThrow(() -> new KeycloakException("Fail to fetch group %s".formatted("club")));
|
||||
|
||||
GroupRepresentation groupRepresentation = new GroupRepresentation();
|
||||
groupRepresentation.setName(club.getId() + "-" + club.getName());
|
||||
|
||||
try (Response response = keycloak.realm(realm).groups().group(clubGroup.getId()).subGroup(groupRepresentation)) {
|
||||
try (Response response =
|
||||
keycloak.realm(realm).groups().group(clubGroup.getId()).subGroup(groupRepresentation)) {
|
||||
if (!response.getStatusInfo().equals(Response.Status.CREATED) && !response.getStatusInfo().equals(Response.Status.CONFLICT))
|
||||
throw new KeycloakException("Fail to set group parent for club: %s (reason=%s)".formatted(club.getName(),
|
||||
response.getStatusInfo().getReasonPhrase()));
|
||||
@ -81,7 +83,8 @@ public class KeycloakService {
|
||||
UserResource user = keycloak.realm(realm).users().get(userId);
|
||||
user.groups().stream().filter(g -> g.getPath().startsWith("/club")).forEach(g -> user.leaveGroup(g.getId()));
|
||||
user.joinGroup(clubId);
|
||||
LOGGER.infof("Set club \"%s\" to user %s (%s)", club.getName(), userId, user.toRepresentation().getUsername());
|
||||
LOGGER.infof("Set club \"%s\" to user %s (%s)", club.getName(), userId,
|
||||
user.toRepresentation().getUsername());
|
||||
return "OK";
|
||||
})));
|
||||
}
|
||||
@ -100,7 +103,8 @@ public class KeycloakService {
|
||||
}
|
||||
|
||||
public Uni<?> setAutoRoleMembre(String id, RoleAsso role, GradeArbitrage gradeArbitrage) {
|
||||
List<String> toRemove = new ArrayList<>(List.of("club_president", "club_tresorier", "club_secretaire", "asseseur", "arbitre"));
|
||||
List<String> toRemove = new ArrayList<>(List.of("club_president", "club_tresorier", "club_secretaire",
|
||||
"asseseur", "arbitre"));
|
||||
List<String> toAdd = new ArrayList<>();
|
||||
|
||||
switch (role) {
|
||||
@ -121,7 +125,8 @@ public class KeycloakService {
|
||||
return vertx.getOrCreateContext().executeBlocking(() -> {
|
||||
UserResource user = keycloak.realm(realm).users().get(id);
|
||||
UserRepresentation user2 = user.toRepresentation();
|
||||
return new Pair<>(user, new UserCompteState(user2.isEnabled(), user2.getUsername(), user2.isEmailVerified()));
|
||||
return new Pair<>(user, new UserCompteState(user2.isEnabled(), user2.getUsername(),
|
||||
user2.isEmailVerified()));
|
||||
});
|
||||
}
|
||||
|
||||
@ -180,12 +185,16 @@ public class KeycloakService {
|
||||
|
||||
try (Response response = keycloak.realm(realm).users().create(user)) {
|
||||
if (!response.getStatusInfo().equals(Response.Status.CREATED) && !response.getStatusInfo().equals(Response.Status.CONFLICT))
|
||||
throw new KeycloakException("Fail to creat user %s (reason=%s)".formatted(login, response.getStatusInfo().getReasonPhrase()));
|
||||
throw new KeycloakException("Fail to creat user %s (reason=%s)".formatted(login,
|
||||
response.getStatusInfo().getReasonPhrase()));
|
||||
}
|
||||
|
||||
String finalLogin = login;
|
||||
return getUser(login).orElseThrow(() -> new KeycloakException("Fail to fetch user %s".formatted(finalLogin)));
|
||||
})
|
||||
.invoke(user -> keycloak.realm(realm).users().get(user.getId())
|
||||
.executeActionsEmail(List.of(RequiredAction.VERIFY_EMAIL.name(),
|
||||
RequiredAction.UPDATE_PASSWORD.name())))
|
||||
.invoke(user -> membreModel.setUserId(user.getId()))
|
||||
.call(user -> membreService.setUserId(membreModel.getId(), user.getId()))
|
||||
.call(user -> setClubGroupMembre(membreModel, membreModel.getClub()));
|
||||
@ -200,7 +209,8 @@ public class KeycloakService {
|
||||
try (Response response = keycloak.realm(realm).users().delete(userId)) {
|
||||
System.out.println(response.getStatusInfo());
|
||||
if (!response.getStatusInfo().equals(Response.Status.NO_CONTENT))
|
||||
throw new KeycloakException("Fail to delete user %s (reason=%s)".formatted(userId, response.getStatusInfo().getReasonPhrase()));
|
||||
throw new KeycloakException("Fail to delete user %s (reason=%s)".formatted(userId,
|
||||
response.getStatusInfo().getReasonPhrase()));
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user