Merge pull request 'mailResources' (#5) from mailResources into master
Reviewed-on: #5
This commit is contained in:
commit
4654eab06e
16
pom.xml
16
pom.xml
@ -64,6 +64,22 @@
|
|||||||
<groupId>io.quarkus</groupId>
|
<groupId>io.quarkus</groupId>
|
||||||
<artifactId>quarkus-smallrye-openapi</artifactId>
|
<artifactId>quarkus-smallrye-openapi</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.quarkus</groupId>
|
||||||
|
<artifactId>quarkus-mailer</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.quarkus</groupId>
|
||||||
|
<artifactId>quarkus-resteasy-mutiny</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.quarkus</groupId>
|
||||||
|
<artifactId>quarkus-resteasy-qute</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.quarkus</groupId>
|
||||||
|
<artifactId>quarkus-redis-client</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.quarkus</groupId>
|
<groupId>io.quarkus</groupId>
|
||||||
<artifactId>quarkus-junit5</artifactId>
|
<artifactId>quarkus-junit5</artifactId>
|
||||||
|
@ -35,7 +35,7 @@ public class ApplicationLifeCycle {
|
|||||||
LOGGER.info("Robert80 user is created");
|
LOGGER.info("Robert80 user is created");
|
||||||
UsersEntity.add("robert80", "robert80@gmail.com", "titi", "robert", LocalDate.of(1990, Month.JANUARY, 23), "toto", "User");
|
UsersEntity.add("robert80", "robert80@gmail.com", "titi", "robert", LocalDate.of(1990, Month.JANUARY, 23), "toto", "User");
|
||||||
LOGGER.info("Peter93 user is created");
|
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 {
|
} else {
|
||||||
LOGGER.info("DB init wassn't created");
|
LOGGER.info("DB init wassn't created");
|
||||||
}
|
}
|
||||||
|
75
src/main/java/com/covas/Resources/MailRessource.java
Normal file
75
src/main/java/com/covas/Resources/MailRessource.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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)
|
# drop and create the database at startup (use `update` to only update the schema)
|
||||||
quarkus.hibernate-orm.database.generation = drop-and-create
|
quarkus.hibernate-orm.database.generation = drop-and-create
|
||||||
|
|
||||||
covas.schema.create = true
|
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
|
||||||
|
3
src/main/resources/templates/mailer.txt
Normal file
3
src/main/resources/templates/mailer.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Coucou {name}
|
||||||
|
|
||||||
|
Voici un lien https://localhost:8080/api/mail/{id}?key={key}
|
Loading…
x
Reference in New Issue
Block a user