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 2d79429..e3e4b11 100644 --- a/src/main/java/org/datasurvey/web/rest/EncuestaResource.java +++ b/src/main/java/org/datasurvey/web/rest/EncuestaResource.java @@ -14,8 +14,12 @@ import org.datasurvey.domain.EPreguntaAbierta; import org.datasurvey.domain.EPreguntaCerrada; import org.datasurvey.domain.EPreguntaCerradaOpcion; import org.datasurvey.domain.Encuesta; +import org.datasurvey.domain.enumeration.AccesoEncuesta; import org.datasurvey.repository.EncuestaRepository; import org.datasurvey.service.*; +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; @@ -46,6 +50,8 @@ public class EncuestaResource { private final EncuestaQueryService encuestaQueryService; + private final MailService mailService; + private final EPreguntaCerradaService ePreguntaCerradaService; private final EPreguntaAbiertaService ePreguntaAbiertaService; @@ -56,6 +62,7 @@ public class EncuestaResource { EncuestaService encuestaService, EncuestaRepository encuestaRepository, EncuestaQueryService encuestaQueryService, + MailService mailService, EPreguntaCerradaService ePreguntaCerradaService, EPreguntaAbiertaService ePreguntaAbiertaService, EPreguntaCerradaOpcionService ePreguntaCerradaOpcionService @@ -63,6 +70,7 @@ public class EncuestaResource { this.encuestaService = encuestaService; this.encuestaRepository = encuestaRepository; this.encuestaQueryService = encuestaQueryService; + this.mailService = mailService; this.ePreguntaCerradaService = ePreguntaCerradaService; this.ePreguntaAbiertaService = ePreguntaAbiertaService; this.ePreguntaCerradaOpcionService = ePreguntaCerradaOpcionService; @@ -116,6 +124,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/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
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 @@
-
+
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); + } + } ); } } 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?" },