diff --git a/src/main/java/org/datasurvey/repository/UserRepository.java b/src/main/java/org/datasurvey/repository/UserRepository.java
index 3f929fb..6a33ce2 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 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/service/UserService.java b/src/main/java/org/datasurvey/service/UserService.java
index 227c590..394274c 100644
--- a/src/main/java/org/datasurvey/service/UserService.java
+++ b/src/main/java/org/datasurvey/service/UserService.java
@@ -76,6 +76,19 @@ public class UserService {
);
}
+ public Optional modifyStatus(String login, Boolean estado) {
+ return userRepository
+ .findOneByLogin(login)
+ .map(
+ user -> {
+ // activate given user for the registration key.
+ user.setActivated(estado);
+ log.debug("Activated user: {}", user);
+ return user;
+ }
+ );
+ }
+
public Optional completePasswordReset(String newPassword, String key) {
log.debug("Reset user password for reset key {}", key);
return userRepository
@@ -386,6 +399,7 @@ public class UserService {
@Transactional(readOnly = true)
public Optional getUserWithAuthorities() {
return SecurityUtils.getCurrentUserLogin().flatMap(userRepository::findOneWithAuthoritiesByLogin);
+ //findOneWithAuthoritiesByLogin
}
/**
diff --git a/src/main/java/org/datasurvey/web/rest/UserJWTController.java b/src/main/java/org/datasurvey/web/rest/UserJWTController.java
index 3ab2601..441b8dd 100644
--- a/src/main/java/org/datasurvey/web/rest/UserJWTController.java
+++ b/src/main/java/org/datasurvey/web/rest/UserJWTController.java
@@ -40,6 +40,7 @@ public class UserJWTController {
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
String jwt = tokenProvider.createToken(authentication, loginVM.isRememberMe());
+
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(JWTFilter.AUTHORIZATION_HEADER, "Bearer " + jwt);
return new ResponseEntity<>(new JWTToken(jwt), httpHeaders, HttpStatus.OK);
diff --git a/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java b/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java
index 9914108..78b9e32 100644
--- a/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java
+++ b/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java
@@ -9,6 +9,8 @@ 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.UserService;
import org.datasurvey.service.UsuarioExtraQueryService;
import org.datasurvey.service.UsuarioExtraService;
import org.datasurvey.service.criteria.UsuarioExtraCriteria;
@@ -41,14 +43,22 @@ public class UsuarioExtraResource {
private final UsuarioExtraQueryService usuarioExtraQueryService;
+ private final MailService mailService;
+
+ private final UserService userService;
+
public UsuarioExtraResource(
UsuarioExtraService usuarioExtraService,
UsuarioExtraRepository usuarioExtraRepository,
- UsuarioExtraQueryService usuarioExtraQueryService
+ UsuarioExtraQueryService usuarioExtraQueryService,
+ MailService mailService,
+ UserService userService
) {
this.usuarioExtraService = usuarioExtraService;
this.usuarioExtraRepository = usuarioExtraRepository;
this.usuarioExtraQueryService = usuarioExtraQueryService;
+ this.mailService = mailService;
+ this.userService = userService;
}
/**
@@ -99,6 +109,40 @@ 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")) {
+ this.userService.modifyStatus(usuarioExtra.getUser().getLogin(), false);
+ mailService.sendSuspendedAccountMail(usuarioExtra); //se manda el correo de la suspecion
+ } else {
+ this.userService.modifyStatus(usuarioExtra.getUser().getLogin(), true);
+ 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..4406c99 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=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,
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/config/error.constants.ts b/src/main/webapp/app/config/error.constants.ts
index ea24e19..e0721f2 100644
--- a/src/main/webapp/app/config/error.constants.ts
+++ b/src/main/webapp/app/config/error.constants.ts
@@ -3,3 +3,4 @@ export const EMAIL_ALREADY_USED_TYPE = PROBLEM_BASE_URL + '/email-already-used';
export const LOGIN_ALREADY_USED_TYPE = PROBLEM_BASE_URL + '/login-already-used';
export const EMAIL_NOT_EXISTS_TYPE = PROBLEM_BASE_URL + '/email-not-exists';
export const USER_IS_GOOGLE_TYPE = PROBLEM_BASE_URL + '/user-is-google';
+export const USER_IS_SUSPENDED = PROBLEM_BASE_URL + '/user-is-suspended';
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 dfe7349..5ac2f58 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,4 +1,4 @@
-
diff --git a/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.spec.ts b/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.spec.ts
deleted file mode 100644
index 4649c87..0000000
--- a/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.spec.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-jest.mock('@ng-bootstrap/ng-bootstrap');
-
-import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing';
-import { HttpResponse } from '@angular/common/http';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { of } from 'rxjs';
-import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
-
-import { UsuarioExtraService } from '../service/usuario-extra.service';
-
-import { UsuarioExtraDeleteDialogComponent } from './usuario-extra-delete-dialog.component';
-
-describe('Component Tests', () => {
- describe('UsuarioExtra Management Delete Component', () => {
- let comp: UsuarioExtraDeleteDialogComponent;
- let fixture: ComponentFixture;
- let service: UsuarioExtraService;
- let mockActiveModal: NgbActiveModal;
-
- beforeEach(() => {
- TestBed.configureTestingModule({
- imports: [HttpClientTestingModule],
- declarations: [UsuarioExtraDeleteDialogComponent],
- providers: [NgbActiveModal],
- })
- .overrideTemplate(UsuarioExtraDeleteDialogComponent, '')
- .compileComponents();
- fixture = TestBed.createComponent(UsuarioExtraDeleteDialogComponent);
- comp = fixture.componentInstance;
- service = TestBed.inject(UsuarioExtraService);
- mockActiveModal = TestBed.inject(NgbActiveModal);
- });
-
- describe('confirmDelete', () => {
- it('Should call delete service on confirmDelete', inject(
- [],
- fakeAsync(() => {
- // GIVEN
- jest.spyOn(service, 'delete').mockReturnValue(of(new HttpResponse({})));
-
- // WHEN
- comp.confirmDelete(123);
- tick();
-
- // THEN
- expect(service.delete).toHaveBeenCalledWith(123);
- expect(mockActiveModal.close).toHaveBeenCalledWith('deleted');
- })
- ));
-
- it('Should not call delete service on clear', () => {
- // GIVEN
- jest.spyOn(service, 'delete');
-
- // WHEN
- comp.cancel();
-
- // THEN
- expect(service.delete).not.toHaveBeenCalled();
- expect(mockActiveModal.close).not.toHaveBeenCalled();
- expect(mockActiveModal.dismiss).toHaveBeenCalled();
- });
- });
- });
-});
diff --git a/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.tmpSpec.ts b/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.tmpSpec.ts
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.ts b/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.ts
index 1f610cc..23e9838 100644
--- a/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.ts
+++ b/src/main/webapp/app/entities/usuario-extra/delete/usuario-extra-delete-dialog.component.ts
@@ -3,6 +3,7 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { IUsuarioExtra } from '../usuario-extra.model';
import { UsuarioExtraService } from '../service/usuario-extra.service';
+import { EstadoUsuario } from '../../enumerations/estado-usuario.model';
@Component({
templateUrl: './usuario-extra-delete-dialog.component.html',
@@ -16,8 +17,13 @@ export class UsuarioExtraDeleteDialogComponent {
this.activeModal.dismiss();
}
- confirmDelete(id: number): void {
- this.usuarioExtraService.delete(id).subscribe(() => {
+ confirmDelete(usuarioExtra: IUsuarioExtra): void {
+ if (usuarioExtra.estado == EstadoUsuario.ACTIVE) {
+ usuarioExtra.estado = EstadoUsuario.SUSPENDED;
+ } else {
+ usuarioExtra.estado = EstadoUsuario.ACTIVE;
+ }
+ this.usuarioExtraService.updateEstado(usuarioExtra).subscribe(() => {
this.activeModal.close('deleted');
});
}
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 a4ce1c6..db78a34 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
@@ -64,9 +64,8 @@
View
-