diff --git a/pom.xml b/pom.xml
index 853ed70..f40a5b9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,6 +64,22 @@
io.quarkus
quarkus-smallrye-openapi
+
+ io.quarkus
+ quarkus-mailer
+
+
+ io.quarkus
+ quarkus-resteasy-mutiny
+
+
+ io.quarkus
+ quarkus-resteasy-qute
+
+
+ io.quarkus
+ quarkus-redis-client
+
io.quarkus
quarkus-junit5
diff --git a/src/main/java/com/covas/ApplicationScoped/ApplicationLifeCycle.java b/src/main/java/com/covas/ApplicationScoped/ApplicationLifeCycle.java
index ecd1721..d617bf8 100644
--- a/src/main/java/com/covas/ApplicationScoped/ApplicationLifeCycle.java
+++ b/src/main/java/com/covas/ApplicationScoped/ApplicationLifeCycle.java
@@ -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");
}
diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java
new file mode 100644
index 0000000..66731fc
--- /dev/null
+++ b/src/main/java/com/covas/Resources/MailRessource.java
@@ -0,0 +1,75 @@
+package com.covas.Resources;
+
+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 io.quarkus.mailer.MailTemplate;
+import io.quarkus.redis.client.RedisClient;
+
+@Path("mail")
+public class MailRessource {
+
+ @Inject
+ private MailTemplate mailer;
+
+ @Inject
+ RedisClient redisClient;
+
+ @GET
+ 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();
+ redisClient.set(Arrays.asList(users.id.toString(),randomKey));
+ redisClient.expire(users.id.toString(), "300");
+ 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}")
+ @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();
+ }
+
+ 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();
+ }
+
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 2d02a15..23993d9 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -11,4 +11,17 @@ quarkus.datasource.jdbc.url = jdbc:postgresql://localhost:5432/toto
# drop and create the database at startup (use `update` to only update the schema)
quarkus.hibernate-orm.database.generation = drop-and-create
-covas.schema.create = true
\ No newline at end of file
+covas.schema.create = true
+
+quarkus.mailer.auth-methods=DIGEST-MD5 CRAM-SHA256 CRAM-SHA1 CRAM-MD5 PLAIN LOGIN
+quarkus.mailer.from=valczebackup@gmail.com
+quarkus.mailer.host=smtp.gmail.com
+quarkus.mailer.port=587
+quarkus.mailer.start-tls=REQUIRED
+quarkus.mailer.username=valczebackup@gmail.com
+quarkus.mailer.password=aohrpmqvxldwyebs
+quarkus.mailer.mock=false
+
+
+
+quarkus.redis.hosts=redis://localhost:6379
diff --git a/src/main/resources/templates/mailer.txt b/src/main/resources/templates/mailer.txt
new file mode 100644
index 0000000..c1c4474
--- /dev/null
+++ b/src/main/resources/templates/mailer.txt
@@ -0,0 +1,3 @@
+Coucou {name}
+
+Voici un lien https://localhost:8080/api/mail/{id}?key={key}