finish redis mail send
This commit is contained in:
parent
4dc921e5ba
commit
5ac8443304
@ -35,7 +35,7 @@ public class ApplicationLifeCycle {
|
||||
LOGGER.info("Robert80 user is created");
|
||||
UsersEntity.add("robert80", "robert80@gmail.com", "titi", "robert", LocalDate.of(1990, Month.JANUARY, 23), "toto", "User");
|
||||
LOGGER.info("Peter93 user is created");
|
||||
UsersEntity.add("peter93", "peter93gmail.com", "yollo", "peter", LocalDate.of(1993, Month.FEBRUARY, 26), "toto", "Admin");
|
||||
UsersEntity.add("peter93", "valcze80@gmail.com", "yollo", "peter", LocalDate.of(1993, Month.FEBRUARY, 26), "toto", "Admin");
|
||||
} else {
|
||||
LOGGER.info("DB init wassn't created");
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
package com.covas.Json;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public class RedisMail {
|
||||
public String key = "";
|
||||
public RedisMail(){
|
||||
key = "";
|
||||
}
|
||||
|
||||
public RedisMail(String key){
|
||||
this.key = key;
|
||||
}
|
||||
}
|
@ -4,16 +4,19 @@ import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import com.covas.Entity.UsersEntity;
|
||||
import com.covas.Json.RedisMail;
|
||||
|
||||
import io.quarkus.mailer.MailTemplate;
|
||||
import io.quarkus.redis.client.RedisClient;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
@Path("mail")
|
||||
public class MailRessource {
|
||||
@ -24,10 +27,10 @@ public class MailRessource {
|
||||
@Inject
|
||||
RedisClient redisClient;
|
||||
|
||||
|
||||
@GET
|
||||
public Response sendMail(UsersEntity users){
|
||||
if(UsersEntity.findByPseudo(users.pseudo) == null){
|
||||
public Response sendMail(UsersEntity usersEntity){
|
||||
UsersEntity users = UsersEntity.findByPseudo(usersEntity.pseudo);
|
||||
if(users == null){
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
String randomKey=UUID.randomUUID().toString();
|
||||
@ -38,15 +41,34 @@ public class MailRessource {
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
public Response activateUsers(@PathParam("id") String id, RedisMail redisMail){
|
||||
if(UsersEntity.findById(UUID.fromString(id)) == null){
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response activateUsers(@PathParam("id") String id, @QueryParam("key") String key){
|
||||
UsersEntity users = UsersEntity.findById(UUID.fromString(id));
|
||||
if(users == null){
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
String redisKey = redisClient.get(id).toString();
|
||||
|
||||
if(!redisKey.equals(redisMail.key)){
|
||||
io.vertx.redis.client.Response singleKey = redisClient.get(id);
|
||||
if(singleKey == null){
|
||||
return Response.status(Response.Status.FORBIDDEN).build();
|
||||
}
|
||||
|
||||
String redisKey = singleKey.toString();
|
||||
|
||||
if(!redisKey.equals(key)){
|
||||
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
|
||||
}
|
||||
redisClient.del(Arrays.asList(id));
|
||||
if(users.active_mail){
|
||||
return Response.status(Response.Status.NOT_MODIFIED).build();
|
||||
}
|
||||
|
||||
users.active_mail = true;
|
||||
users.persist();
|
||||
|
||||
if(users.isPersistent()){
|
||||
return Response.status(Response.Status.PARTIAL_CONTENT).build();
|
||||
}
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user