From a85e6b161ef96c4c51b843bd320e4ec36265e7a2 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 14 Aug 2022 18:52:20 +0200 Subject: [PATCH] add check email and pseudo --- .../com/covas/Resources/UsersRessources.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 3f4b8c4..e734e59 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -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