modificacion de estado en el user

This commit is contained in:
Paola 2021-07-22 19:32:39 -06:00
parent b04c75edd2
commit 262897d07c
6 changed files with 36 additions and 29 deletions

View File

@ -76,6 +76,19 @@ public class UserService {
); );
} }
public Optional<User> 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<User> completePasswordReset(String newPassword, String key) { public Optional<User> completePasswordReset(String newPassword, String key) {
log.debug("Reset user password for reset key {}", key); log.debug("Reset user password for reset key {}", key);
return userRepository return userRepository

View File

@ -10,6 +10,7 @@ import javax.validation.constraints.NotNull;
import org.datasurvey.domain.UsuarioExtra; import org.datasurvey.domain.UsuarioExtra;
import org.datasurvey.repository.UsuarioExtraRepository; import org.datasurvey.repository.UsuarioExtraRepository;
import org.datasurvey.service.MailService; import org.datasurvey.service.MailService;
import org.datasurvey.service.UserService;
import org.datasurvey.service.UsuarioExtraQueryService; import org.datasurvey.service.UsuarioExtraQueryService;
import org.datasurvey.service.UsuarioExtraService; import org.datasurvey.service.UsuarioExtraService;
import org.datasurvey.service.criteria.UsuarioExtraCriteria; import org.datasurvey.service.criteria.UsuarioExtraCriteria;
@ -44,16 +45,20 @@ public class UsuarioExtraResource {
private final MailService mailService; private final MailService mailService;
private final UserService userService;
public UsuarioExtraResource( public UsuarioExtraResource(
UsuarioExtraService usuarioExtraService, UsuarioExtraService usuarioExtraService,
UsuarioExtraRepository usuarioExtraRepository, UsuarioExtraRepository usuarioExtraRepository,
UsuarioExtraQueryService usuarioExtraQueryService, UsuarioExtraQueryService usuarioExtraQueryService,
MailService mailService MailService mailService,
UserService userService
) { ) {
this.usuarioExtraService = usuarioExtraService; this.usuarioExtraService = usuarioExtraService;
this.usuarioExtraRepository = usuarioExtraRepository; this.usuarioExtraRepository = usuarioExtraRepository;
this.usuarioExtraQueryService = usuarioExtraQueryService; this.usuarioExtraQueryService = usuarioExtraQueryService;
this.mailService = mailService; this.mailService = mailService;
this.userService = userService;
} }
/** /**
@ -131,8 +136,10 @@ public class UsuarioExtraResource {
UsuarioExtra result = usuarioExtraService.save(usuarioExtra); UsuarioExtra result = usuarioExtraService.save(usuarioExtra);
if (usuarioExtra.getEstado().name().equals("SUSPENDED")) { if (usuarioExtra.getEstado().name().equals("SUSPENDED")) {
this.userService.modifyStatus(usuarioExtra.getUser().getLogin(), false);
mailService.sendSuspendedAccountMail(usuarioExtra); //se manda el correo de la suspecion mailService.sendSuspendedAccountMail(usuarioExtra); //se manda el correo de la suspecion
} else { } else {
this.userService.modifyStatus(usuarioExtra.getUser().getLogin(), true);
mailService.sendActivatedAccountMail(usuarioExtra); //se manda el correo de reactivacion mailService.sendActivatedAccountMail(usuarioExtra); //se manda el correo de reactivacion
} }

View File

@ -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 LOGIN_ALREADY_USED_TYPE = PROBLEM_BASE_URL + '/login-already-used';
export const EMAIL_NOT_EXISTS_TYPE = PROBLEM_BASE_URL + '/email-not-exists'; 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_GOOGLE_TYPE = PROBLEM_BASE_URL + '/user-is-google';
export const USER_IS_SUSPENDED = PROBLEM_BASE_URL + '/user-is-suspended';

View File

@ -83,6 +83,13 @@
<strong>Failed to sign in!</strong> Please check your credentials and try again. <strong>Failed to sign in!</strong> Please check your credentials and try again.
</div> </div>
<div
class="alert alert-danger"
*ngIf="userSuspended"
jhiTranslate="login.messages.error.userSuspended"
data-cy="loginError"
></div>
<form class="ds-form" role="form" (ngSubmit)="login()" [formGroup]="loginForm"> <form class="ds-form" role="form" (ngSubmit)="login()" [formGroup]="loginForm">
<div class="mb-3"> <div class="mb-3">
<div class="form-group"> <div class="form-group">

View File

@ -9,7 +9,7 @@ import { GoogleLoginProvider } from 'angularx-social-login';
import { RegisterService } from '../account/register/register.service'; import { RegisterService } from '../account/register/register.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { HttpErrorResponse } from '@angular/common/http'; 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'; import { LocalStorageService } from 'ngx-webstorage';
@Component({ @Component({
@ -25,6 +25,8 @@ export class LoginComponent implements OnInit, AfterViewInit {
error = false; error = false;
errorEmailExists = false; errorEmailExists = false;
errorUserExists = false; errorUserExists = false;
userSuspended = false;
imprimir = false;
loginForm = this.fb.group({ loginForm = this.fb.group({
username: [null, [Validators.required, Validators.email, Validators.maxLength(254)]], username: [null, [Validators.required, Validators.email, Validators.maxLength(254)]],
@ -48,18 +50,6 @@ export class LoginComponent implements OnInit, AfterViewInit {
) {} ) {}
ngOnInit(): void { 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 // if already authenticated then navigate to home page
this.accountService.identity().subscribe(() => { this.accountService.identity().subscribe(() => {
if (this.accountService.isAuthenticated()) { if (this.accountService.isAuthenticated()) {
@ -99,20 +89,6 @@ export class LoginComponent implements OnInit, AfterViewInit {
} }
}, },
() => this.activateGoogle() () => 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; this.errorUserExists = true;
} else if (response.status === 400 && response.error.type === EMAIL_ALREADY_USED_TYPE) { } else if (response.status === 400 && response.error.type === EMAIL_ALREADY_USED_TYPE) {
this.errorEmailExists = true; this.errorEmailExists = true;
} else if (response.status === 401 && response.error.type === USER_IS_SUSPENDED) {
this.userSuspended = true;
} else { } else {
this.error = true; this.error = true;
} }

View File

@ -10,7 +10,8 @@
"messages": { "messages": {
"error": { "error": {
"authentication": "Revise las credenciales e intente de nuevo ", "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": { "password": {