add post function
This commit is contained in:
parent
e3dbd0b5d1
commit
b48f2bc73a
@ -14,6 +14,7 @@ import javax.ws.rs.CookieParam;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.PATCH;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
@ -120,12 +121,47 @@ public class UsersRessources {
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
// POST
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Transactional
|
||||
public Response createUser(UsersEntity users) {
|
||||
Response.Status status = Response.Status.OK;
|
||||
UsersEntity usersOrig = UsersEntity.findByPseudo(users.pseudo);
|
||||
if (usersOrig != null) {
|
||||
status = Response.Status.UNAUTHORIZED;
|
||||
} else {
|
||||
UsersEntity usersNew = new UsersEntity();
|
||||
usersNew.name = users.name;
|
||||
usersNew.pseudo = users.pseudo;
|
||||
usersNew.firstName = users.firstName;
|
||||
usersNew.email = users.email;
|
||||
usersNew.birth = LocalDate.of(users.birth.getYear(), users.birth.getMonth(),
|
||||
users.birth.getDayOfMonth());
|
||||
usersNew.created_at = LocalDateTime.now();
|
||||
usersNew.updated_at = LocalDateTime.now();
|
||||
usersNew.password = Hash
|
||||
.encryptSHA512(Base64.toBase64String(users.password.getBytes(StandardCharsets.UTF_8)));
|
||||
usersNew.roles = users.roles;
|
||||
usersNew.status = false;
|
||||
usersNew.active_mail = false;
|
||||
usersNew.persist();
|
||||
if (usersNew.isPersistent()) {
|
||||
status = Response.Status.CREATED;
|
||||
} else {
|
||||
status = Response.Status.NO_CONTENT;
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
|
||||
// PUT
|
||||
@PUT
|
||||
@RolesAllowed("Admin")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Transactional
|
||||
public Response createUser(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||
public Response addUser(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||
UsersEntity users) {
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
|
Loading…
x
Reference in New Issue
Block a user