From b04c75edd2ed338a9088dd92d56e2ecb2e436572 Mon Sep 17 00:00:00 2001
From: Paola
Date: Thu, 22 Jul 2021 01:51:08 -0600
Subject: [PATCH 1/7] envio de correos en cambio de estado usuario
---
.../org/datasurvey/service/MailService.java | 13 +
.../web/rest/UsuarioExtraResource.java | 39 ++-
src/main/resources/i18n/messages.properties | 12 +
.../resources/i18n/messages_es.properties | 12 +
.../templates/mail/creationEmail.html | 2 +-
.../mail/reactivatedAccountEmail.html | 322 ++++++++++++++++++
.../templates/mail/suspendedAccountEmail.html | 319 +++++++++++++++++
...usuario-extra-delete-dialog.component.html | 2 +-
.../usuario-extra-delete-dialog.component.ts | 10 +-
.../service/usuario-extra.service.ts | 8 +
10 files changed, 734 insertions(+), 5 deletions(-)
create mode 100644 src/main/resources/templates/mail/reactivatedAccountEmail.html
create mode 100644 src/main/resources/templates/mail/suspendedAccountEmail.html
diff --git a/src/main/java/org/datasurvey/service/MailService.java b/src/main/java/org/datasurvey/service/MailService.java
index c40c4fe..cf8f62b 100644
--- a/src/main/java/org/datasurvey/service/MailService.java
+++ b/src/main/java/org/datasurvey/service/MailService.java
@@ -5,6 +5,7 @@ import java.util.Locale;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.datasurvey.domain.User;
+import org.datasurvey.domain.UsuarioExtra;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
@@ -115,4 +116,16 @@ public class MailService {
log.debug("Sending password restored email to '{}'", user.getEmail());
sendEmailFromTemplate(user, "mail/passwordRestoredEmail", "email.restored.title");
}
+
+ @Async
+ public void sendSuspendedAccountMail(UsuarioExtra user) {
+ log.debug("Sending suspended account mail to '{}'", user.getUser().getEmail());
+ sendEmailFromTemplate(user.getUser(), "mail/suspendedAccountEmail", "email.suspended.title");
+ }
+
+ @Async
+ public void sendActivatedAccountMail(UsuarioExtra user) {
+ log.debug("Sending reactivated account mail to '{}'", user.getUser().getEmail());
+ sendEmailFromTemplate(user.getUser(), "mail/reactivatedAccountEmail", "email.reactivation.title");
+ }
}
diff --git a/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java b/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java
index 9914108..c5d5c35 100644
--- a/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java
+++ b/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java
@@ -9,6 +9,7 @@ import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.datasurvey.domain.UsuarioExtra;
import org.datasurvey.repository.UsuarioExtraRepository;
+import org.datasurvey.service.MailService;
import org.datasurvey.service.UsuarioExtraQueryService;
import org.datasurvey.service.UsuarioExtraService;
import org.datasurvey.service.criteria.UsuarioExtraCriteria;
@@ -41,14 +42,18 @@ public class UsuarioExtraResource {
private final UsuarioExtraQueryService usuarioExtraQueryService;
+ private final MailService mailService;
+
public UsuarioExtraResource(
UsuarioExtraService usuarioExtraService,
UsuarioExtraRepository usuarioExtraRepository,
- UsuarioExtraQueryService usuarioExtraQueryService
+ UsuarioExtraQueryService usuarioExtraQueryService,
+ MailService mailService
) {
this.usuarioExtraService = usuarioExtraService;
this.usuarioExtraRepository = usuarioExtraRepository;
this.usuarioExtraQueryService = usuarioExtraQueryService;
+ this.mailService = mailService;
}
/**
@@ -99,6 +104,38 @@ public class UsuarioExtraResource {
}
UsuarioExtra result = usuarioExtraService.save(usuarioExtra);
+
+ return ResponseEntity
+ .ok()
+ .headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, usuarioExtra.getId().toString()))
+ .body(result);
+ }
+
+ @PutMapping("/usuario-extras-estado/{id}")
+ public ResponseEntity updateUsuarioExtraEstado(
+ @PathVariable(value = "id", required = false) final Long id,
+ @Valid @RequestBody UsuarioExtra usuarioExtra
+ ) throws URISyntaxException {
+ log.debug("REST request to update UsuarioExtra : {}, {}", id, usuarioExtra);
+ if (usuarioExtra.getId() == null) {
+ throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
+ }
+ if (!Objects.equals(id, usuarioExtra.getId())) {
+ throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
+ }
+
+ if (!usuarioExtraRepository.existsById(id)) {
+ throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
+ }
+
+ UsuarioExtra result = usuarioExtraService.save(usuarioExtra);
+
+ if (usuarioExtra.getEstado().name().equals("SUSPENDED")) {
+ mailService.sendSuspendedAccountMail(usuarioExtra); //se manda el correo de la suspecion
+ } else {
+ mailService.sendActivatedAccountMail(usuarioExtra); //se manda el correo de reactivacion
+ }
+
return ResponseEntity
.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, usuarioExtra.getId().toString()))
diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties
index 52b6575..7ff70ce 100644
--- a/src/main/resources/i18n/messages.properties
+++ b/src/main/resources/i18n/messages.properties
@@ -27,3 +27,15 @@ email.restored.text1=Your DataSurvey password has been successfully reset..
email.restored.text2=Regards,
email.restored.text3=If you did not make this change, please notify the following email immediately:
email.restored.email=datasurvey@gmail.com
+
+#reactivar la cuenta
+email.reactivation.title=Your account has been reactivated
+email.reactivation.greeting=Hello, {0}!
+email.reactivation.text1=Your account has been reactivated. Please click on the link so you can keep enjoying DataSurvey:
+email.reactivation.text2=Regards,
+
+#suspended accounr
+email.suspended.title=Your account has been suspended
+email.suspended.greeting=Dear {0}
+email.suspended.text1=Su cuenta en DatSurvey se encuentra temporalmente suspendida. Si cree que es un error por favor haga clic en el siguiente enlace para enviar una solicitud para reactivar su cuenta:
+email.suspended.text2=Saludos,
diff --git a/src/main/resources/i18n/messages_es.properties b/src/main/resources/i18n/messages_es.properties
index 77121fd..a9bc280 100644
--- a/src/main/resources/i18n/messages_es.properties
+++ b/src/main/resources/i18n/messages_es.properties
@@ -28,3 +28,15 @@ email.restored.text2=Saludos,
email.restored.text3=Si usted no realizó este cambio, favor notifique inmediatamente al siguiente correo:
email.restored.email=datasurvey@gmail.com
+#reactivate account
+email.reactivation.title=Su cuenta ha sido reactivada
+email.reactivation.greeting=¡Hola, {0}!
+email.reactivation.text1=Su cuenta en DataSurvey ha sido reactivada. Por favor haga clic en el siguiente enlace para iniciar sesión y disfrutar de DataSurvey:
+email.reactivation.text2=Saludos,
+
+
+#suspended accounr
+email.suspended.title=Su cuenta ha sido suspendida
+email.suspended.greeting=Querido {0}
+email.suspended.text1=Lamentamos informarle que su cuenta en DatSurvey se encuentra temporalmente suspendida. Si cree que es un error por favor haga clic en el siguiente enlace para enviar una solicitud para reactivar su cuenta:
+email.suspended.text2=Saludos,
diff --git a/src/main/resources/templates/mail/creationEmail.html b/src/main/resources/templates/mail/creationEmail.html
index 68b86f5..e46861a 100644
--- a/src/main/resources/templates/mail/creationEmail.html
+++ b/src/main/resources/templates/mail/creationEmail.html
@@ -264,7 +264,7 @@
th:with="url=(@{|${baseUrl}/account/reset/finish?key=${user.resetKey}|})"
th:href="${url}"
class="btn btn-primary"
- >Iniciar sesiónIniciar Sesión
diff --git a/src/main/resources/templates/mail/reactivatedAccountEmail.html b/src/main/resources/templates/mail/reactivatedAccountEmail.html
new file mode 100644
index 0000000..8226a4d
--- /dev/null
+++ b/src/main/resources/templates/mail/reactivatedAccountEmail.html
@@ -0,0 +1,322 @@
+
+
+
+
+
+
+
+
+
+
+ JHipster activation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+ |
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+ ¡Hola!
+
+ Your JHipster account has been created, please click on the URL below to activate it:
+
+
+ Iniciar Sesión
+
+
+
+
+ Regards,
+
+ JHipster.
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/templates/mail/suspendedAccountEmail.html b/src/main/resources/templates/mail/suspendedAccountEmail.html
new file mode 100644
index 0000000..5cc146b
--- /dev/null
+++ b/src/main/resources/templates/mail/suspendedAccountEmail.html
@@ -0,0 +1,319 @@
+
+
+
+
+
+
+
+
+
+
+ JHipster activation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+ |
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+ ¡Hola!
+
+ Your JHipster account has been created, please click on the URL below to activate it:
+
+
+
+
+ Regards,
+
+ JHipster.
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.html b/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.html
index 805ea79..3d4ac3c 100644
--- a/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.html
+++ b/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.html
@@ -1,4 +1,4 @@
-