add check email and pseudo
This commit is contained in:
parent
f64640db45
commit
2d6953dc29
@ -8,6 +8,7 @@ import javax.persistence.Column;
|
|||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import com.covas.Classes.Hash;
|
import com.covas.Classes.Hash;
|
||||||
@ -56,6 +57,10 @@ public class UsersEntity extends PanacheEntityBase {
|
|||||||
return find("pseudo", pseudo).firstResult();
|
return find("pseudo", pseudo).firstResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static UsersEntity findByEmail(String email){
|
||||||
|
return find("email", email).firstResult();
|
||||||
|
}
|
||||||
|
|
||||||
public static void add(String pseudo, String email, String name, String firstName, LocalDate birth, String password, String roles){
|
public static void add(String pseudo, String email, String name, String firstName, LocalDate birth, String password, String roles){
|
||||||
|
|
||||||
UsersEntity users = new UsersEntity();
|
UsersEntity users = new UsersEntity();
|
||||||
|
16
src/main/java/com/covas/Json/UserExist.java
Normal file
16
src/main/java/com/covas/Json/UserExist.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package com.covas.Json;
|
||||||
|
|
||||||
|
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||||
|
|
||||||
|
@RegisterForReflection
|
||||||
|
public class UserExist {
|
||||||
|
|
||||||
|
public final Boolean email;
|
||||||
|
public final Boolean pseudo;
|
||||||
|
|
||||||
|
public UserExist(Boolean email, Boolean pseudo){
|
||||||
|
this.email = email;
|
||||||
|
this.pseudo = pseudo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,6 +9,7 @@ import javax.annotation.security.RolesAllowed;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
import javax.ws.rs.core.SecurityContext;
|
import javax.ws.rs.core.SecurityContext;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.CookieParam;
|
import javax.ws.rs.CookieParam;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
@ -26,6 +27,7 @@ import javax.ws.rs.core.Response;
|
|||||||
|
|
||||||
import com.covas.Classes.Hash;
|
import com.covas.Classes.Hash;
|
||||||
import com.covas.Entity.UsersEntity;
|
import com.covas.Entity.UsersEntity;
|
||||||
|
import com.covas.Json.UserExist;
|
||||||
import com.covas.Json.UserSingle;
|
import com.covas.Json.UserSingle;
|
||||||
|
|
||||||
import io.quarkus.panache.common.Page;
|
import io.quarkus.panache.common.Page;
|
||||||
@ -150,10 +152,23 @@ public class UsersRessources {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public Response createUser(UsersEntity users) {
|
public Response createUser(UsersEntity users) {
|
||||||
Response.Status status = Response.Status.OK;
|
Response.Status status = Response.Status.OK;
|
||||||
UsersEntity usersOrig = UsersEntity.findByPseudo(users.pseudo);
|
UsersEntity usersPseudo = UsersEntity.findByPseudo(users.pseudo);
|
||||||
if (usersOrig != null) {
|
UsersEntity usersEmail = UsersEntity.findByPseudo(users.email);
|
||||||
|
Boolean createUserBool = true;
|
||||||
|
Boolean pseudoExist = false;
|
||||||
|
Boolean emailExist = false;
|
||||||
|
if (usersPseudo != null) {
|
||||||
|
createUserBool = false;
|
||||||
status = Response.Status.UNAUTHORIZED;
|
status = Response.Status.UNAUTHORIZED;
|
||||||
} else {
|
pseudoExist = true;
|
||||||
|
}
|
||||||
|
if(usersEmail != null){
|
||||||
|
createUserBool = false;
|
||||||
|
status = Response.Status.UNAUTHORIZED;
|
||||||
|
emailExist = true;
|
||||||
|
}
|
||||||
|
UserExist userExist = new UserExist(emailExist, pseudoExist);
|
||||||
|
if(createUserBool) {
|
||||||
UsersEntity usersNew = new UsersEntity();
|
UsersEntity usersNew = new UsersEntity();
|
||||||
usersNew.name = users.name;
|
usersNew.name = users.name;
|
||||||
usersNew.pseudo = users.pseudo;
|
usersNew.pseudo = users.pseudo;
|
||||||
@ -174,7 +189,7 @@ public class UsersRessources {
|
|||||||
status = Response.Status.NO_CONTENT;
|
status = Response.Status.NO_CONTENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Response.status(status).build();
|
return Response.status(status).entity(userExist).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user