mail resources with redis
This commit is contained in:
parent
d36a7f8e41
commit
dce878dc04
15
src/main/java/com/covas/Json/RedisMail.java
Normal file
15
src/main/java/com/covas/Json/RedisMail.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ import javax.ws.rs.PathParam;
|
|||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import com.covas.Entity.UsersEntity;
|
import com.covas.Entity.UsersEntity;
|
||||||
|
import com.covas.Json.RedisMail;
|
||||||
|
|
||||||
import io.quarkus.mailer.MailTemplate;
|
import io.quarkus.mailer.MailTemplate;
|
||||||
import io.quarkus.redis.client.RedisClient;
|
import io.quarkus.redis.client.RedisClient;
|
||||||
@ -29,16 +30,23 @@ public class MailRessource {
|
|||||||
if(UsersEntity.findByPseudo(users.pseudo) == null){
|
if(UsersEntity.findByPseudo(users.pseudo) == null){
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
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();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@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){
|
if(UsersEntity.findById(UUID.fromString(id)) == null){
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
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();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +1,3 @@
|
|||||||
Coucou {name} !
|
Coucou {name}
|
||||||
|
|
||||||
|
Voici un lien https://localhost:8080/api/mail/{id}?key={key}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user