From 6663fb729d1aa018abf4bf21af11c1c34b1d9484 Mon Sep 17 00:00:00 2001 From: Paola Date: Sat, 24 Jul 2021 22:53:38 -0600 Subject: [PATCH 1/4] agreacion contrasenna encuesta y arreglo cache --- .../datasurvey/config/CacheConfiguration.java | 7 +- .../datasurvey/repository/UserRepository.java | 2 +- .../org/datasurvey/service/MailService.java | 30 ++ .../org/datasurvey/service/UserService.java | 4 + .../datasurvey/web/rest/EncuestaResource.java | 14 +- src/main/resources/i18n/messages.properties | 13 + .../resources/i18n/messages_es.properties | 12 + .../templates/mail/encuestaPrivadaEmail.html | 319 ++++++++++++++++++ .../templates/mail/encuestaPublicaEmail.html | 319 ++++++++++++++++++ .../webapp/app/core/auth/account.service.ts | 1 + .../encuesta-publish-dialog.component.ts | 17 + .../list/usuario-extra.component.html | 7 +- .../list/usuario-extra.component.ts | 2 + .../webapp/app/login/login.component.html | 9 +- src/main/webapp/app/login/login.component.ts | 18 +- 15 files changed, 764 insertions(+), 10 deletions(-) create mode 100644 src/main/resources/templates/mail/encuestaPrivadaEmail.html create mode 100644 src/main/resources/templates/mail/encuestaPublicaEmail.html diff --git a/src/main/java/org/datasurvey/config/CacheConfiguration.java b/src/main/java/org/datasurvey/config/CacheConfiguration.java index 0836c99..0e82862 100644 --- a/src/main/java/org/datasurvey/config/CacheConfiguration.java +++ b/src/main/java/org/datasurvey/config/CacheConfiguration.java @@ -24,13 +24,13 @@ public class CacheConfiguration { private final javax.cache.configuration.Configuration jcacheConfiguration; public CacheConfiguration(JHipsterProperties jHipsterProperties) { - JHipsterProperties.Cache.Ehcache ehcache = jHipsterProperties.getCache().getEhcache(); + //JHipsterProperties.Cache.Ehcache ehcache = jHipsterProperties.getCache().getEhcache(); jcacheConfiguration = Eh107Configuration.fromEhcacheCacheConfiguration( CacheConfigurationBuilder - .newCacheConfigurationBuilder(Object.class, Object.class, ResourcePoolsBuilder.heap(ehcache.getMaxEntries())) - .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(ehcache.getTimeToLiveSeconds()))) + .newCacheConfigurationBuilder(Object.class, Object.class, ResourcePoolsBuilder.heap(100L)) + .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(1))) .build() ); } @@ -82,6 +82,7 @@ public class CacheConfiguration { private void createCache(javax.cache.CacheManager cm, String cacheName) { javax.cache.Cache cache = cm.getCache(cacheName); + if (cache != null) { cache.clear(); } else { diff --git a/src/main/java/org/datasurvey/repository/UserRepository.java b/src/main/java/org/datasurvey/repository/UserRepository.java index 6a33ce2..3f929fb 100644 --- a/src/main/java/org/datasurvey/repository/UserRepository.java +++ b/src/main/java/org/datasurvey/repository/UserRepository.java @@ -31,7 +31,7 @@ public interface UserRepository extends JpaRepository { Optional findOneByLogin(String login); @EntityGraph(attributePaths = "authorities") - //@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE) + @Cacheable(cacheNames = USERS_BY_LOGIN_CACHE) Optional findOneWithAuthoritiesByLogin(String login); @EntityGraph(attributePaths = "authorities") diff --git a/src/main/java/org/datasurvey/service/MailService.java b/src/main/java/org/datasurvey/service/MailService.java index cf8f62b..a14a8e8 100644 --- a/src/main/java/org/datasurvey/service/MailService.java +++ b/src/main/java/org/datasurvey/service/MailService.java @@ -30,6 +30,8 @@ public class MailService { private static final String USER = "user"; + private static final String CONTRASENNA = "contrasenna"; + private static final String BASE_URL = "baseUrl"; private final JHipsterProperties jHipsterProperties; @@ -93,6 +95,22 @@ public class MailService { sendEmail(user.getEmail(), subject, content, false, true); } + @Async + public void sendEmailFromTemplateEncuesta(User user, String templateName, String titleKey, String contrasenna) { + if (user.getEmail() == null) { + log.debug("Email doesn't exist for user '{}'", user.getLogin()); + return; + } + Locale locale = Locale.forLanguageTag(user.getLangKey()); + Context context = new Context(locale); + context.setVariable(CONTRASENNA, contrasenna); + context.setVariable(USER, user); + context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl()); + String content = templateEngine.process(templateName, context); + String subject = messageSource.getMessage(titleKey, null, locale); + sendEmail(user.getEmail(), subject, content, false, true); + } + @Async public void sendActivationEmail(User user) { log.debug("Sending activation email to '{}'", user.getEmail()); @@ -128,4 +146,16 @@ public class MailService { log.debug("Sending reactivated account mail to '{}'", user.getUser().getEmail()); sendEmailFromTemplate(user.getUser(), "mail/reactivatedAccountEmail", "email.reactivation.title"); } + + @Async + public void sendPublishedPrivateMail(UsuarioExtra user, String contrasenna) { + log.debug("Sending reactivated account mail to '{}'", user.getUser().getEmail()); + sendEmailFromTemplateEncuesta(user.getUser(), "mail/encuestaPrivadaEmail", "email.private.title", contrasenna); + } + + @Async + public void sendPublishedPublicMail(UsuarioExtra user) { + log.debug("Sending reactivated account mail to '{}'", user.getUser().getEmail()); + sendEmailFromTemplate(user.getUser(), "mail/encuestaPublicaEmail", "email.public.title"); + } } diff --git a/src/main/java/org/datasurvey/service/UserService.java b/src/main/java/org/datasurvey/service/UserService.java index 394274c..76f47ec 100644 --- a/src/main/java/org/datasurvey/service/UserService.java +++ b/src/main/java/org/datasurvey/service/UserService.java @@ -394,12 +394,16 @@ public class UserService { @Transactional(readOnly = true) public Optional getUserWithAuthoritiesByLogin(String login) { return userRepository.findOneWithAuthoritiesByLogin(login); + //cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE).clear(); } @Transactional(readOnly = true) public Optional getUserWithAuthorities() { return SecurityUtils.getCurrentUserLogin().flatMap(userRepository::findOneWithAuthoritiesByLogin); //findOneWithAuthoritiesByLogin + //cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE).clear(); + + //return user; } /** diff --git a/src/main/java/org/datasurvey/web/rest/EncuestaResource.java b/src/main/java/org/datasurvey/web/rest/EncuestaResource.java index bcf74c8..7245119 100644 --- a/src/main/java/org/datasurvey/web/rest/EncuestaResource.java +++ b/src/main/java/org/datasurvey/web/rest/EncuestaResource.java @@ -8,9 +8,11 @@ import java.util.Optional; import javax.validation.Valid; import javax.validation.constraints.NotNull; import org.datasurvey.domain.Encuesta; +import org.datasurvey.domain.enumeration.AccesoEncuesta; import org.datasurvey.repository.EncuestaRepository; import org.datasurvey.service.EncuestaQueryService; import org.datasurvey.service.EncuestaService; +import org.datasurvey.service.MailService; import org.datasurvey.service.criteria.EncuestaCriteria; import org.datasurvey.web.rest.errors.BadRequestAlertException; import org.slf4j.Logger; @@ -41,14 +43,18 @@ public class EncuestaResource { private final EncuestaQueryService encuestaQueryService; + private final MailService mailService; + public EncuestaResource( EncuestaService encuestaService, EncuestaRepository encuestaRepository, - EncuestaQueryService encuestaQueryService + EncuestaQueryService encuestaQueryService, + MailService mailService ) { this.encuestaService = encuestaService; this.encuestaRepository = encuestaRepository; this.encuestaQueryService = encuestaQueryService; + this.mailService = mailService; } /** @@ -99,6 +105,12 @@ public class EncuestaResource { } Encuesta result = encuestaService.save(encuesta); + + if (result.getAcceso().equals(AccesoEncuesta.PRIVATE)) { + mailService.sendPublishedPrivateMail(result.getUsuarioExtra(), result.getContrasenna()); + } else { + mailService.sendPublishedPublicMail(result.getUsuarioExtra()); + } return ResponseEntity .ok() .headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, encuesta.getId().toString())) diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index 7ff70ce..6239473 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -39,3 +39,16 @@ 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, + +#PublicEncuesta +email.public.title=Su encuesta ha sido publicada +email.public.greeting=¡Felicidades {0}! +email.public.text1=Su encuesta ha sido publicada de manera publica +email.public.text2=Saludos, + +#PrivateEncuesta +email.private.title=Su encuesta ha sido publicada de manera privada +email.private.greeting=¡Felicidades {0}! +email.private.text1=Su encuesta ha sdo publicada de manera privada. Su contraseña de acceso es: {0} +email.private.text2=Saludos, + diff --git a/src/main/resources/i18n/messages_es.properties b/src/main/resources/i18n/messages_es.properties index 4406c99..7c205b5 100644 --- a/src/main/resources/i18n/messages_es.properties +++ b/src/main/resources/i18n/messages_es.properties @@ -40,3 +40,15 @@ email.suspended.title=Su cuenta ha sido suspendida email.suspended.greeting=Estimado {0} email.suspended.text1=Lamentamos informarle que su cuenta en DatSurvey se encuentra temporalmente suspendida. Si cree que es un error por favor responda a este correo email.suspended.text2=Saludos, + +#PublicEncuesta +email.public.title=Su encuesta ha sido publicada +email.public.greeting=¡Felicidades {0}! +email.public.text1=Su encuesta ha sido publicada de manera publica +email.public.text2=Saludos, + +#PrivateEncuesta +email.private.title=Su encuesta ha sido publicada de manera privada +email.private.greeting=¡Felicidades {0}! +email.private.text1=Su encuesta ha sdo publicada de manera privada. Su contraseña de acceso es: {0} +email.private.text2=Saludos, diff --git a/src/main/resources/templates/mail/encuestaPrivadaEmail.html b/src/main/resources/templates/mail/encuestaPrivadaEmail.html new file mode 100644 index 0000000..b017e8b --- /dev/null +++ b/src/main/resources/templates/mail/encuestaPrivadaEmail.html @@ -0,0 +1,319 @@ + + + + + + + + + + + JHipster activation + + + + + + + +
+
+ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌  +
+ +
+ + diff --git a/src/main/resources/templates/mail/encuestaPublicaEmail.html b/src/main/resources/templates/mail/encuestaPublicaEmail.html new file mode 100644 index 0000000..f4a1dda --- /dev/null +++ b/src/main/resources/templates/mail/encuestaPublicaEmail.html @@ -0,0 +1,319 @@ + + + + + + + + + + + JHipster activation + + + + + + + +
+
+ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌  +
+ +
+ + diff --git a/src/main/webapp/app/core/auth/account.service.ts b/src/main/webapp/app/core/auth/account.service.ts index 324c77e..b28fd53 100644 --- a/src/main/webapp/app/core/auth/account.service.ts +++ b/src/main/webapp/app/core/auth/account.service.ts @@ -72,6 +72,7 @@ export class AccountService { shareReplay() ); } + return this.accountCache$; } diff --git a/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.ts b/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.ts index ff2d3b5..dae745d 100644 --- a/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.ts +++ b/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.ts @@ -3,6 +3,8 @@ import { IEncuesta } from '../encuesta.model'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { EncuestaService } from '../service/encuesta.service'; import { EstadoEncuesta } from '../../enumerations/estado-encuesta.model'; +import { AccesoEncuesta } from '../../enumerations/acceso-encuesta.model'; +import { passwordResetFinishRoute } from '../../../account/password-reset/finish/password-reset-finish.route'; @Component({ selector: 'jhi-encuesta-publish-dialog', @@ -24,10 +26,25 @@ export class EncuestaPublishDialogComponent implements OnInit { encuesta.estado = EstadoEncuesta.ACTIVE; } + if (encuesta.acceso === AccesoEncuesta.PRIVATE) { + encuesta.contrasenna = this.generatePassword(); + } + this.encuestaService.update(encuesta).subscribe(() => { this.activeModal.close('published'); }); } + generatePassword(): string { + debugger; + const alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; + + let password = ''; + for (let i = 0; i < 5; i++) { + password += alpha.charAt(Math.floor(Math.random() * alpha.length)); + } + return password; + } + ngOnInit(): void {} } diff --git a/src/main/webapp/app/entities/usuario-extra/list/usuario-extra.component.html b/src/main/webapp/app/entities/usuario-extra/list/usuario-extra.component.html index db78a34..9ccef39 100644 --- a/src/main/webapp/app/entities/usuario-extra/list/usuario-extra.component.html +++ b/src/main/webapp/app/entities/usuario-extra/list/usuario-extra.component.html @@ -12,7 +12,12 @@ - +
No usuarioExtras found diff --git a/src/main/webapp/app/entities/usuario-extra/list/usuario-extra.component.ts b/src/main/webapp/app/entities/usuario-extra/list/usuario-extra.component.ts index 3588bf3..49199d8 100644 --- a/src/main/webapp/app/entities/usuario-extra/list/usuario-extra.component.ts +++ b/src/main/webapp/app/entities/usuario-extra/list/usuario-extra.component.ts @@ -17,6 +17,7 @@ export class UsuarioExtraComponent implements OnInit { usuarioExtras?: IUsuarioExtra[]; publicUsers?: IUser[]; isLoading = false; + successChange = false; constructor(protected usuarioExtraService: UsuarioExtraService, protected modalService: NgbModal) {} @@ -73,6 +74,7 @@ export class UsuarioExtraComponent implements OnInit { // unsubscribe not needed because closed completes on modal close modalRef.closed.subscribe(reason => { if (reason === 'deleted') { + this.successChange = true; this.loadAll(); } }); diff --git a/src/main/webapp/app/login/login.component.html b/src/main/webapp/app/login/login.component.html index c47e7d8..4918e58 100644 --- a/src/main/webapp/app/login/login.component.html +++ b/src/main/webapp/app/login/login.component.html @@ -74,13 +74,18 @@

Ingrese su correo electrónico y contraseña

-
+
Failed to sign in! Please check your credentials and try again.
diff --git a/src/main/webapp/app/login/login.component.ts b/src/main/webapp/app/login/login.component.ts index 1dade60..2c79da7 100644 --- a/src/main/webapp/app/login/login.component.ts +++ b/src/main/webapp/app/login/login.component.ts @@ -81,6 +81,9 @@ export class LoginComponent implements OnInit, AfterViewInit { } authenticacionGoogle(): void { + this.error = false; + this.userSuspended = false; + this.loginService.login({ username: this.user.email, password: this.user.id, rememberMe: false }).subscribe( () => { this.authenticationError = false; @@ -123,6 +126,9 @@ export class LoginComponent implements OnInit, AfterViewInit { } activateGoogle(): void { + this.error = false; + this.userSuspended = false; + this.registerService .save({ login: this.user.email, @@ -145,6 +151,8 @@ export class LoginComponent implements OnInit, AfterViewInit { } login(): void { + this.error = false; + this.userSuspended = false; debugger; this.loginService .login({ @@ -169,8 +177,14 @@ export class LoginComponent implements OnInit, AfterViewInit { } // } }, - - response => this.processError(response) + response => { + debugger; + if (response.status == 401 && response.error.detail == 'Bad credentials') { + this.error = true; + } else { + this.processError(response); + } + } ); } } From b5de3a3ee6bd2e8d630b126b0f7dd1b93db54967 Mon Sep 17 00:00:00 2001 From: Paola Date: Sat, 24 Jul 2021 23:11:16 -0600 Subject: [PATCH 2/4] arreglo alerta categorias --- .../categoria/list/categoria.component.html | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/webapp/app/entities/categoria/list/categoria.component.html b/src/main/webapp/app/entities/categoria/list/categoria.component.html index 2ee3101..7fb1898 100644 --- a/src/main/webapp/app/entities/categoria/list/categoria.component.html +++ b/src/main/webapp/app/entities/categoria/list/categoria.component.html @@ -19,12 +19,17 @@
--> -
- + -
-
No categorias found
From 4eec11079f34cfced4d0faa728b1ab9c4cf2c462 Mon Sep 17 00:00:00 2001 From: Paola Date: Sat, 24 Jul 2021 23:17:30 -0600 Subject: [PATCH 3/4] Arreglo encuestas filter --- .../webapp/app/entities/encuesta/list/encuesta.component.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts b/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts index 6014017..f6389cc 100644 --- a/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts +++ b/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts @@ -149,7 +149,8 @@ export class EncuestaComponent implements OnInit, AfterViewInit { this.isLoading = false; const tmpEncuestas = res.body ?? []; if (this.isAdmin()) { - this.encuestas = tmpEncuestas; + this.encuestas = tmpEncuestas.filter(e => e.estado !== EstadoEncuesta.DELETED); + this.encuestas.forEach(e => { e.usuarioExtra = this.usuarioExtrasSharedCollection?.find(pU => pU.id == e.usuarioExtra?.id); }); From fcd87cb6358cef0e244fad68136633ef29f4f865 Mon Sep 17 00:00:00 2001 From: Paola Date: Sun, 25 Jul 2021 00:34:52 -0600 Subject: [PATCH 4/4] Arreglo mensajes alerta --- .../encuesta-delete-dialog.component.html | 4 +-- .../encuesta/list/encuesta.component.html | 2 +- src/main/webapp/app/home/home.component.html | 35 ++++++++++--------- src/main/webapp/i18n/es/encuesta.json | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.html b/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.html index 89c4a44..a21389e 100644 --- a/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.html +++ b/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.html @@ -1,8 +1,8 @@
diff --git a/src/main/webapp/i18n/es/encuesta.json b/src/main/webapp/i18n/es/encuesta.json index ab8c85b..cd755ab 100644 --- a/src/main/webapp/i18n/es/encuesta.json +++ b/src/main/webapp/i18n/es/encuesta.json @@ -12,7 +12,7 @@ "updated": "Una encuesta ha sido actualizado con el identificador {{ param }}", "deleted": "Una encuesta ha sido eliminada con el identificador {{ param }}", "delete": { - "question": "¿Seguro que quiere eliminar la encuesta {{ id }}?", + "question": "¿Seguro que quiere eliminar la encuesta?", "deletequestion": "¿Seguro que quiere eliminar esta pregunta?", "deleteoption": "¿Seguro que quiere eliminar esta opción?" },