add check email and pseudo

This commit is contained in:
Valentin CZERYBA 2022-08-14 18:52:20 +02:00
parent 2d6953dc29
commit a85e6b161e

View File

@ -153,7 +153,7 @@ public class UsersRessources {
public Response createUser(UsersEntity users) {
Response.Status status = Response.Status.OK;
UsersEntity usersPseudo = UsersEntity.findByPseudo(users.pseudo);
UsersEntity usersEmail = UsersEntity.findByPseudo(users.email);
UsersEntity usersEmail = UsersEntity.findByEmail(users.email);
Boolean createUserBool = true;
Boolean pseudoExist = false;
Boolean emailExist = false;
@ -167,7 +167,6 @@ public class UsersRessources {
status = Response.Status.UNAUTHORIZED;
emailExist = true;
}
UserExist userExist = new UserExist(emailExist, pseudoExist);
if(createUserBool) {
UsersEntity usersNew = new UsersEntity();
usersNew.name = users.name;
@ -189,7 +188,7 @@ public class UsersRessources {
status = Response.Status.NO_CONTENT;
}
}
return Response.status(status).entity(userExist).build();
return Response.status(status).entity(new UserExist(emailExist, pseudoExist)).build();
}
@ -203,13 +202,26 @@ public class UsersRessources {
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
UsersEntity user = UsersEntity.findById(kid);
Response.Status status = getResponseCheck(ctx, userCookie, user);
Boolean pseudoExist = false;
Boolean emailExist = false;
if (status.equals(Response.Status.OK)) {
UsersEntity usersOrig = UsersEntity.findByPseudo(users.pseudo);
if (usersOrig != null) {
UsersEntity usersPseudo = UsersEntity.findByPseudo(users.pseudo);
UsersEntity usersEmail = UsersEntity.findByEmail(users.email);
Boolean createUserBool = true;
if (usersPseudo != null) {
createUserBool = false;
status = Response.Status.UNAUTHORIZED;
} else {
pseudoExist = true;
}
if(usersEmail != null){
createUserBool = false;
status = Response.Status.UNAUTHORIZED;
emailExist = true;
}
if(createUserBool) {
UsersEntity usersNew = new UsersEntity();
usersNew.name = users.name;
usersNew.pseudo = users.pseudo;
@ -231,7 +243,7 @@ public class UsersRessources {
}
}
}
return Response.status(status).build();
return Response.status(status).entity(new UserExist(emailExist, pseudoExist)).build();
}
// Delete