diff --git a/src/main/java/org/datasurvey/service/UserService.java b/src/main/java/org/datasurvey/service/UserService.java index 227c590..8d4b49c 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 diff --git a/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java b/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java index c5d5c35..78b9e32 100644 --- a/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java +++ b/src/main/java/org/datasurvey/web/rest/UsuarioExtraResource.java @@ -10,6 +10,7 @@ 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; @@ -44,16 +45,20 @@ public class UsuarioExtraResource { private final MailService mailService; + private final UserService userService; + public UsuarioExtraResource( UsuarioExtraService usuarioExtraService, UsuarioExtraRepository usuarioExtraRepository, UsuarioExtraQueryService usuarioExtraQueryService, - MailService mailService + MailService mailService, + UserService userService ) { this.usuarioExtraService = usuarioExtraService; this.usuarioExtraRepository = usuarioExtraRepository; this.usuarioExtraQueryService = usuarioExtraQueryService; this.mailService = mailService; + this.userService = userService; } /** @@ -131,8 +136,10 @@ public class UsuarioExtraResource { 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 } 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/login/login.component.html b/src/main/webapp/app/login/login.component.html index 1a2c917..6755ff1 100644 --- a/src/main/webapp/app/login/login.component.html +++ b/src/main/webapp/app/login/login.component.html @@ -83,6 +83,13 @@ 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 b0a4685..e2d8b24 100644 --- a/src/main/webapp/app/login/login.component.ts +++ b/src/main/webapp/app/login/login.component.ts @@ -9,7 +9,7 @@ import { GoogleLoginProvider } from 'angularx-social-login'; import { RegisterService } from '../account/register/register.service'; import { TranslateService } from '@ngx-translate/core'; import { HttpErrorResponse } from '@angular/common/http'; -import { EMAIL_ALREADY_USED_TYPE, LOGIN_ALREADY_USED_TYPE } from '../config/error.constants'; +import { EMAIL_ALREADY_USED_TYPE, LOGIN_ALREADY_USED_TYPE, USER_IS_SUSPENDED } from '../config/error.constants'; import { LocalStorageService } from 'ngx-webstorage'; @Component({ @@ -25,6 +25,8 @@ export class LoginComponent implements OnInit, AfterViewInit { error = false; errorEmailExists = false; errorUserExists = false; + userSuspended = false; + imprimir = false; loginForm = this.fb.group({ username: [null, [Validators.required, Validators.email, Validators.maxLength(254)]], @@ -48,18 +50,6 @@ export class LoginComponent implements OnInit, AfterViewInit { ) {} ngOnInit(): void { - //Servicio para verificar si el usuario se encuentra loggeado - /*this.authService.authState.subscribe(user => { - this.user = user; - this.loggedIn = user != null; - - /!* console.log('correo: ' + user.email); - console.log('correo: ' + user.name); - console.log('ID: ' + this.user.id);*!/ - - this.authenticacionGoogle(); - }); -*/ // if already authenticated then navigate to home page this.accountService.identity().subscribe(() => { if (this.accountService.isAuthenticated()) { @@ -99,20 +89,6 @@ export class LoginComponent implements OnInit, AfterViewInit { } }, () => this.activateGoogle() - /*this.registerService - .save({ - login: this.user.email, - email: this.user.email, - password: this.user.id, - langKey: this.translateService.currentLang, - name: this.user.name, - profileIcon: this.randomProfilePic(), - isAdmin: 0, - }) - .subscribe( - () => (this.success = true), - response => this.processError(response) - ) */ //console.log("Usuario no existe") ); } @@ -125,6 +101,8 @@ export class LoginComponent implements OnInit, AfterViewInit { this.errorUserExists = true; } else if (response.status === 400 && response.error.type === EMAIL_ALREADY_USED_TYPE) { this.errorEmailExists = true; + } else if (response.status === 401 && response.error.type === USER_IS_SUSPENDED) { + this.userSuspended = true; } else { this.error = true; } diff --git a/src/main/webapp/i18n/es/login.json b/src/main/webapp/i18n/es/login.json index 9266406..29dd15d 100644 --- a/src/main/webapp/i18n/es/login.json +++ b/src/main/webapp/i18n/es/login.json @@ -10,7 +10,8 @@ "messages": { "error": { "authentication": "Revise las credenciales e intente de nuevo ", - "isGoogle": "Al haber ingresado por medio de Google no cuenta con los permisos para modificar su contraseña" + "isGoogle": "Al haber ingresado por medio de Google no cuenta con los permisos para modificar su contraseña", + "userSuspended": "No cuenta con los permisos para iniciar sesión, su cuenta se encuentra suspendida" } }, "password": {