mail resources with redis

This commit is contained in:
Valentin CZERYBA 2022-06-15 23:25:13 +02:00
parent d36a7f8e41
commit dce878dc04
3 changed files with 28 additions and 3 deletions

View File

@ -0,0 +1,15 @@
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;
}
}

View File

@ -10,6 +10,7 @@ import javax.ws.rs.PathParam;
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;
@ -29,16 +30,23 @@ public class MailRessource {
if(UsersEntity.findByPseudo(users.pseudo) == null){
return Response.status(Response.Status.NOT_FOUND).build();
}
mailer.to("valcze808@gmail.com").subject("test").data("name", "Robert").send().subscribeAsCompletionStage();
String randomKey=UUID.randomUUID().toString();
redisClient.set(Arrays.asList(users.id.toString(),randomKey));
mailer.to(users.email).subject(String.format("Compte %s créée", users.email)).data("name", users.pseudo).data("id",users.id).data("key",randomKey).send().subscribeAsCompletionStage();
return Response.ok().build();
}
@GET
@Path("{id}")
public Response activateUsers(@PathParam("id") String id){
public Response activateUsers(@PathParam("id") String id, RedisMail redisMail){
if(UsersEntity.findById(UUID.fromString(id)) == null){
return Response.status(Response.Status.NOT_FOUND).build();
}
String redisKey = redisClient.get(id).toString();
if(!redisKey.equals(redisMail.key)){
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
}
return Response.ok().build();
}

View File

@ -1 +1,3 @@
Coucou {name} !
Coucou {name}
Voici un lien https://localhost:8080/api/mail/{id}?key={key}