From 3a5d89c5fb8dc268ea80879786388af3ee9569d5 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 30 May 2022 22:41:12 +0200 Subject: [PATCH 01/12] create resources --- pom.xml | 4 ++++ .../com/covas/Resources/MailRessource.java | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/main/java/com/covas/Resources/MailRessource.java diff --git a/pom.xml b/pom.xml index 853ed70..7956250 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,10 @@ io.quarkus quarkus-smallrye-openapi + + io.quarkus + quarkus-mailer + io.quarkus quarkus-junit5 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..ff47261 --- /dev/null +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -0,0 +1,23 @@ +package com.covas.Resources; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import io.quarkus.mailer.Mail; +import io.quarkus.mailer.reactive.ReactiveMailer; +import io.smallrye.mutiny.Uni; + +@Path("mail") +public class MailRessource { + + @Inject + private ReactiveMailer mail; + + @GET + public Uni sendMail(){ + return mail.send(Mail.withText("valcze80@gmail.com", "toto", "toto")); + } + + +} From a9cafc90daa5f4296473899f19398948bd6e4a24 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 30 May 2022 23:13:58 +0200 Subject: [PATCH 02/12] config mail --- pom.xml | 4 ++++ src/main/resources/application.properties | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7956250..f15c87c 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,10 @@ io.quarkus quarkus-mailer + + io.quarkus + quarkus-resteasy-mutiny + io.quarkus quarkus-junit5 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2d02a15..69c99b0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -11,4 +11,12 @@ 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=465 +quarkus.mailer.ssl=true +quarkus.mailer.username=valczebackup@gmail.com +quarkus.mailer.password=aohrpmqvxldwyebs \ No newline at end of file From 9464408bf98474a7029a4a6b23e6b7276d84b332 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 5 Jun 2022 19:00:45 +0200 Subject: [PATCH 03/12] test mail ok --- .../java/com/covas/Resources/MailRessource.java | 14 +++++++++++--- src/main/resources/application.properties | 7 ++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java index ff47261..b87aee6 100644 --- a/src/main/java/com/covas/Resources/MailRessource.java +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -1,12 +1,17 @@ package com.covas.Resources; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; + import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.core.Response; import io.quarkus.mailer.Mail; +import io.quarkus.mailer.Mailer; import io.quarkus.mailer.reactive.ReactiveMailer; -import io.smallrye.mutiny.Uni; + @Path("mail") public class MailRessource { @@ -14,9 +19,12 @@ public class MailRessource { @Inject private ReactiveMailer mail; + @GET - public Uni sendMail(){ - return mail.send(Mail.withText("valcze80@gmail.com", "toto", "toto")); + public CompletionStage sendMail(){ + return mail.send(Mail.withText("valcze80@gmail.com", "async", "toto")) + .subscribeAsCompletionStage() + .thenApply(x -> Response.accepted().build()); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 69c99b0..efaf00f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -16,7 +16,8 @@ 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=465 -quarkus.mailer.ssl=true +quarkus.mailer.port=587 +quarkus.mailer.start-tls=REQUIRED quarkus.mailer.username=valczebackup@gmail.com -quarkus.mailer.password=aohrpmqvxldwyebs \ No newline at end of file +quarkus.mailer.password=aohrpmqvxldwyebs +quarkus.mailer.mock=false \ No newline at end of file From 4dedad452845ce87339c3bf2139b4b976fa61bad Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 6 Jun 2022 19:58:07 +0200 Subject: [PATCH 04/12] template mail --- pom.xml | 4 ++++ .../java/com/covas/Resources/MailRessource.java | 13 +++++++++---- src/main/resources/templates/hello.txt | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/templates/hello.txt diff --git a/pom.xml b/pom.xml index f15c87c..7eafd45 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,10 @@ io.quarkus quarkus-resteasy-mutiny + + io.quarkus + quarkus-resteasy-qute + io.quarkus quarkus-junit5 diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java index b87aee6..cc979dc 100644 --- a/src/main/java/com/covas/Resources/MailRessource.java +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -9,7 +9,7 @@ import javax.ws.rs.Path; import javax.ws.rs.core.Response; import io.quarkus.mailer.Mail; -import io.quarkus.mailer.Mailer; +import io.quarkus.mailer.MailTemplate; import io.quarkus.mailer.reactive.ReactiveMailer; @@ -19,12 +19,17 @@ public class MailRessource { @Inject private ReactiveMailer mail; + @Inject + private MailTemplate hello; + @GET + @Path("async") public CompletionStage sendMail(){ - return mail.send(Mail.withText("valcze80@gmail.com", "async", "toto")) - .subscribeAsCompletionStage() - .thenApply(x -> Response.accepted().build()); + //return mail.send(Mail.withText("valcze80@gmail.com", "async", "toto")) + //.subscribeAsCompletionStage() + //.thenApply(x -> Response.accepted().build()); + return hello.to("valcze80@gmail.com").subject("test").data("name", "Robert").send().subscribeAsCompletionStage().thenApply(x -> Response.accepted().build()); } diff --git a/src/main/resources/templates/hello.txt b/src/main/resources/templates/hello.txt new file mode 100644 index 0000000..9a61208 --- /dev/null +++ b/src/main/resources/templates/hello.txt @@ -0,0 +1 @@ +Coucou {name} ! \ No newline at end of file From b2389b5ef865574589ae189789747313afffba16 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 11 Jun 2022 00:24:32 +0200 Subject: [PATCH 05/12] Transform return GET in Response Imperative --- .../com/covas/Resources/MailRessource.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java index cc979dc..d97a839 100644 --- a/src/main/java/com/covas/Resources/MailRessource.java +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -1,35 +1,32 @@ package com.covas.Resources; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; +import java.util.concurrent.Flow; import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.core.Response; -import io.quarkus.mailer.Mail; -import io.quarkus.mailer.MailTemplate; -import io.quarkus.mailer.reactive.ReactiveMailer; +import io.quarkus.mailer.MailTemplate; +import io.quarkus.qute.CheckedTemplate; +import io.smallrye.mutiny.Uni; @Path("mail") public class MailRessource { - @Inject - private ReactiveMailer mail; - @Inject private MailTemplate hello; - + + + @GET - @Path("async") - public CompletionStage sendMail(){ - //return mail.send(Mail.withText("valcze80@gmail.com", "async", "toto")) - //.subscribeAsCompletionStage() - //.thenApply(x -> Response.accepted().build()); - return hello.to("valcze80@gmail.com").subject("test").data("name", "Robert").send().subscribeAsCompletionStage().thenApply(x -> Response.accepted().build()); + public Response sendMail(){ + + hello.to("valcze808@gmail.com").subject("test").data("name", "Robert").send().subscribeAsCompletionStage(); + return Response.ok().build(); } From 824d75dfcd61f3c393f8bdf5e004213b950b8131 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 12 Jun 2022 00:11:48 +0200 Subject: [PATCH 06/12] fix mail --- .../com/covas/Resources/MailRessource.java | 20 ++++++++++++++++--- .../templates/{hello.txt => mailer.txt} | 0 2 files changed, 17 insertions(+), 3 deletions(-) rename src/main/resources/templates/{hello.txt => mailer.txt} (100%) diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java index d97a839..5cdc2ad 100644 --- a/src/main/java/com/covas/Resources/MailRessource.java +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -1,13 +1,16 @@ package com.covas.Resources; +import java.util.UUID; import java.util.concurrent.CompletionStage; import java.util.concurrent.Flow; import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; +import com.covas.Entity.UsersEntity; import io.quarkus.mailer.MailTemplate; import io.quarkus.qute.CheckedTemplate; @@ -17,15 +20,26 @@ import io.smallrye.mutiny.Uni; public class MailRessource { @Inject - private MailTemplate hello; + private MailTemplate mailer; @GET - public Response sendMail(){ + public Response sendMail(UsersEntity users){ + 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(); + return Response.ok().build(); + } - hello.to("valcze808@gmail.com").subject("test").data("name", "Robert").send().subscribeAsCompletionStage(); + @GET + @Path("{id}") + public Response activateUsers(@PathParam("id") String id){ + if(UsersEntity.findById(UUID.fromString(id)) == null){ + return Response.status(Response.Status.NOT_FOUND).build(); + } return Response.ok().build(); } diff --git a/src/main/resources/templates/hello.txt b/src/main/resources/templates/mailer.txt similarity index 100% rename from src/main/resources/templates/hello.txt rename to src/main/resources/templates/mailer.txt From 180d25cfcbec4e757c23b7a2e80077a34d024b73 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 12 Jun 2022 00:34:05 +0200 Subject: [PATCH 07/12] redis work in progress --- pom.xml | 4 ++++ .../com/covas/Resources/MailRessource.java | 22 ++++++++++++++----- src/main/resources/application.properties | 7 +++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 7eafd45..f40a5b9 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,10 @@ io.quarkus quarkus-resteasy-qute + + io.quarkus + quarkus-redis-client + io.quarkus quarkus-junit5 diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java index 5cdc2ad..e475f9f 100644 --- a/src/main/java/com/covas/Resources/MailRessource.java +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -1,8 +1,7 @@ package com.covas.Resources; +import java.util.Arrays; import java.util.UUID; -import java.util.concurrent.CompletionStage; -import java.util.concurrent.Flow; import javax.inject.Inject; import javax.ws.rs.GET; @@ -13,8 +12,7 @@ import javax.ws.rs.core.Response; import com.covas.Entity.UsersEntity; import io.quarkus.mailer.MailTemplate; -import io.quarkus.qute.CheckedTemplate; -import io.smallrye.mutiny.Uni; +import io.quarkus.redis.client.RedisClient; @Path("mail") public class MailRessource { @@ -22,8 +20,9 @@ public class MailRessource { @Inject private MailTemplate mailer; + @Inject + RedisClient redisClient; - @GET public Response sendMail(UsersEntity users){ @@ -43,5 +42,18 @@ public class MailRessource { return Response.ok().build(); } + @GET + @Path("set-redis") + public Response setRedis(){ + redisClient.set(Arrays.asList("toto","sss")); + return Response.ok().build(); + } + + @GET + @Path("get-redis/{id}") + public Response getRedis(@PathParam("id") String id){ + return Response.ok().entity(redisClient.get(id)).build(); + } + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index efaf00f..60ba02a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -20,4 +20,9 @@ quarkus.mailer.port=587 quarkus.mailer.start-tls=REQUIRED quarkus.mailer.username=valczebackup@gmail.com quarkus.mailer.password=aohrpmqvxldwyebs -quarkus.mailer.mock=false \ No newline at end of file +quarkus.mailer.mock=false + + + +quarkus.redis.hosts=redis://localhost:6379 + From d36a7f8e416b0b449467afb73d6d0aadb58b0d83 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 13 Jun 2022 23:07:36 +0200 Subject: [PATCH 08/12] fix trouble redis --- src/main/java/com/covas/Resources/MailRessource.java | 2 +- src/main/resources/application.properties | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java index e475f9f..a157725 100644 --- a/src/main/java/com/covas/Resources/MailRessource.java +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -52,7 +52,7 @@ public class MailRessource { @GET @Path("get-redis/{id}") public Response getRedis(@PathParam("id") String id){ - return Response.ok().entity(redisClient.get(id)).build(); + return Response.ok().entity(redisClient.get(id).toString()).build(); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 60ba02a..23993d9 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -24,5 +24,4 @@ quarkus.mailer.mock=false -quarkus.redis.hosts=redis://localhost:6379 - +quarkus.redis.hosts=redis://localhost:6379 From dce878dc04fadcd99e6256dfc4bae9051601dc39 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 15 Jun 2022 23:25:13 +0200 Subject: [PATCH 09/12] mail resources with redis --- src/main/java/com/covas/Json/RedisMail.java | 15 +++++++++++++++ .../java/com/covas/Resources/MailRessource.java | 12 ++++++++++-- src/main/resources/templates/mailer.txt | 4 +++- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/covas/Json/RedisMail.java diff --git a/src/main/java/com/covas/Json/RedisMail.java b/src/main/java/com/covas/Json/RedisMail.java new file mode 100644 index 0000000..e5792b0 --- /dev/null +++ b/src/main/java/com/covas/Json/RedisMail.java @@ -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; + } +} diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java index a157725..9205b2a 100644 --- a/src/main/java/com/covas/Resources/MailRessource.java +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -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(); } diff --git a/src/main/resources/templates/mailer.txt b/src/main/resources/templates/mailer.txt index 9a61208..c1c4474 100644 --- a/src/main/resources/templates/mailer.txt +++ b/src/main/resources/templates/mailer.txt @@ -1 +1,3 @@ -Coucou {name} ! \ No newline at end of file +Coucou {name} + +Voici un lien https://localhost:8080/api/mail/{id}?key={key} From 4dc921e5baa0f4e0af820454b5d1061eff7c4d74 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 15 Jun 2022 23:26:00 +0200 Subject: [PATCH 10/12] remove function get useless --- .../java/com/covas/Resources/MailRessource.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java index 9205b2a..5a8edf2 100644 --- a/src/main/java/com/covas/Resources/MailRessource.java +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -49,19 +49,5 @@ public class MailRessource { } return Response.ok().build(); } - - @GET - @Path("set-redis") - public Response setRedis(){ - redisClient.set(Arrays.asList("toto","sss")); - return Response.ok().build(); - } - - @GET - @Path("get-redis/{id}") - public Response getRedis(@PathParam("id") String id){ - return Response.ok().entity(redisClient.get(id).toString()).build(); - } - } From 5ac8443304d9db760ccfb0c22f91f98278cb961d Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 23 Jun 2022 23:44:00 +0200 Subject: [PATCH 11/12] finish redis mail send --- .../ApplicationLifeCycle.java | 2 +- src/main/java/com/covas/Json/RedisMail.java | 15 -------- .../com/covas/Resources/MailRessource.java | 38 +++++++++++++++---- 3 files changed, 31 insertions(+), 24 deletions(-) delete mode 100644 src/main/java/com/covas/Json/RedisMail.java 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/Json/RedisMail.java b/src/main/java/com/covas/Json/RedisMail.java deleted file mode 100644 index e5792b0..0000000 --- a/src/main/java/com/covas/Json/RedisMail.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java index 5a8edf2..c006301 100644 --- a/src/main/java/com/covas/Resources/MailRessource.java +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -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(); + + 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(redisMail.key)){ + 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(); } From de5990fa62d141f7ba3fec98096e9b7f04f1516d Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 27 Jun 2022 23:05:17 +0200 Subject: [PATCH 12/12] add expire 5 minutes for mail --- src/main/java/com/covas/Resources/MailRessource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java index c006301..66731fc 100644 --- a/src/main/java/com/covas/Resources/MailRessource.java +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -16,7 +16,6 @@ import com.covas.Entity.UsersEntity; import io.quarkus.mailer.MailTemplate; import io.quarkus.redis.client.RedisClient; -import org.jboss.logging.Logger; @Path("mail") public class MailRessource { @@ -35,6 +34,7 @@ public class MailRessource { } 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(); }