Merge pull request #18 from Quantum-P3/fix/log-in

validaciones log in
This commit is contained in:
Eduardo Quiros 2021-07-11 21:29:46 +00:00 committed by GitHub
commit 81b550b3c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 7 deletions

View File

@ -36,6 +36,7 @@ export class AuthServerProvider {
return new Observable(observer => { return new Observable(observer => {
this.localStorageService.clear('authenticationToken'); this.localStorageService.clear('authenticationToken');
this.sessionStorageService.clear('authenticationToken'); this.sessionStorageService.clear('authenticationToken');
this.localStorageService.clear('IsGoogle');
observer.complete(); observer.complete();
}); });
} }

View File

@ -6,7 +6,7 @@ import { Account } from 'app/core/auth/account.model';
import { AccountService } from 'app/core/auth/account.service'; import { AccountService } from 'app/core/auth/account.service';
import { LoginService } from 'app/login/login.service'; import { LoginService } from 'app/login/login.service';
import { ProfileService } from 'app/layouts/profiles/profile.service'; import { ProfileService } from 'app/layouts/profiles/profile.service';
import { SessionStorageService } from 'ngx-webstorage'; import { LocalStorageService, SessionStorageService } from 'ngx-webstorage';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { UsuarioExtraService } from 'app/entities/usuario-extra/service/usuario-extra.service'; import { UsuarioExtraService } from 'app/entities/usuario-extra/service/usuario-extra.service';
import { UsuarioExtra } from 'app/entities/usuario-extra/usuario-extra.model'; import { UsuarioExtra } from 'app/entities/usuario-extra/usuario-extra.model';
@ -31,6 +31,7 @@ export class SidebarComponent {
constructor( constructor(
private loginService: LoginService, private loginService: LoginService,
private sessionStorageService: SessionStorageService, private sessionStorageService: SessionStorageService,
private localStorageService: LocalStorageService,
private accountService: AccountService, private accountService: AccountService,
private profileService: ProfileService, private profileService: ProfileService,
private router: Router, private router: Router,
@ -87,6 +88,7 @@ export class SidebarComponent {
this.collapseNavbar(); this.collapseNavbar();
this.loginService.logout(); this.loginService.logout();
this.router.navigate(['']); this.router.navigate(['']);
this.localStorageService.clear('IsGoogle');
} }
toggleNavbar(): void { toggleNavbar(): void {

View File

@ -71,7 +71,7 @@
<h4 class="text-dark-50 text-center pb-0 fw-bold p-0 m-0" style="color: #727070; font-weight: 700; font-size: 1.3rem"> <h4 class="text-dark-50 text-center pb-0 fw-bold p-0 m-0" style="color: #727070; font-weight: 700; font-size: 1.3rem">
INICIAR SESION INICIAR SESION
</h4> </h4>
<p class="mb-4" style="color: rgba(146, 146, 146, 0.664)">Ingrese su correo electrónico y contraseña.</p> <p class="mb-4" style="color: rgba(146, 146, 146, 0.664)">Ingrese su correo electrónico y contraseña</p>
</div> </div>
<div <div
@ -82,10 +82,11 @@
> >
<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>
<form class="form" role="form" (ngSubmit)="login()" [formGroup]="loginForm"> <form class="form" role="form" (ngSubmit)="login()" [formGroup]="loginForm">
<div class="mb-3"> <div class="mb-3">
<div class="form-group"> <div class="form-group">
<label for="emailaddress" class="form-label">Correo electrónico</label> <label for="username" class="form-label">Correo electrónico</label>
<input <input
type="text" type="text"
class="form-control" class="form-control"
@ -96,6 +97,41 @@
#username #username
data-cy="username" data-cy="username"
/> />
<div
*ngIf="loginForm.get('username')!.invalid && (loginForm.get('username')!.dirty || loginForm.get('username')!.touched)"
>
<small
class="form-text text-danger"
*ngIf="loginForm.get('username')?.errors?.required"
jhiTranslate="global.messages.validate.email.required"
>
Your email is required.
</small>
<small
class="form-text text-danger"
*ngIf="loginForm.get('username')?.errors?.invalid"
jhiTranslate="global.messages.validate.email.invalid"
>
Your email is invalid.
</small>
<small
class="form-text text-danger"
*ngIf="loginForm.get('username')?.errors?.minlength"
jhiTranslate="global.messages.validate.email.minlength"
>
Your email is required to be at least 5 characters.
</small>
<small
class="form-text text-danger"
*ngIf="loginForm.get('username')?.errors?.maxlength"
jhiTranslate="global.messages.validate.email.maxlength"
>
Your email cannot be longer than 100 characters.
</small>
</div>
</div> </div>
</div> </div>
@ -111,6 +147,33 @@
formControlName="password" formControlName="password"
data-cy="password" data-cy="password"
/> />
<div
*ngIf="loginForm.get('password')!.invalid && (loginForm.get('password')!.dirty || loginForm.get('password')!.touched)"
>
<small
class="form-text text-danger"
*ngIf="loginForm.get('password')?.errors?.required"
jhiTranslate="global.messages.validate.newpassword.required"
>
Your password is required.
</small>
<small
class="form-text text-danger"
*ngIf="loginForm.get('password')?.errors?.minlength"
jhiTranslate="global.messages.validate.newpassword.minlength"
>
Your password is required to be at least 4 characters.
</small>
<small
class="form-text text-danger"
*ngIf="loginForm.get('password')?.errors?.maxlength"
jhiTranslate="global.messages.validate.newpassword.maxlength"
>
Your password cannot be longer than 50 characters.
</small>
</div>
</div> </div>
</div> </div>

View File

@ -10,6 +10,7 @@ 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 } from '../config/error.constants';
import { LocalStorageService } from 'ngx-webstorage';
@Component({ @Component({
selector: 'jhi-login', selector: 'jhi-login',
@ -26,8 +27,8 @@ export class LoginComponent implements OnInit, AfterViewInit {
errorUserExists = false; errorUserExists = false;
loginForm = this.fb.group({ loginForm = this.fb.group({
username: [null, [Validators.required]], username: [null, [Validators.required, Validators.email, Validators.minLength(5), Validators.maxLength(254)]],
password: [null, [Validators.required]], password: [null, [Validators.required, Validators.minLength(4), Validators.maxLength(50)]],
rememberMe: [false], rememberMe: [false],
}); });
@ -36,6 +37,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
success = false; success = false;
constructor( constructor(
private localStorageService: LocalStorageService,
private accountService: AccountService, private accountService: AccountService,
private loginService: LoginService, private loginService: LoginService,
private router: Router, private router: Router,
@ -91,7 +93,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
() => { () => {
this.authenticationError = false; this.authenticationError = false;
if (!this.router.getCurrentNavigation()) { if (!this.router.getCurrentNavigation()) {
window.localStorage.setItem('IsGoogle', 'true'); this.localStorageService.store('IsGoogle', 'true');
// There were no routing during login (eg from navigationToStoredUrl) // There were no routing during login (eg from navigationToStoredUrl)
this.router.navigate(['']); this.router.navigate(['']);
} }

View File

@ -9,7 +9,7 @@
}, },
"messages": { "messages": {
"error": { "error": {
"authentication": "<strong>¡El inicio de sesión ha fallado!</strong> Por favor, revise las credenciales e intente de nuevo." "authentication": "Revise las credenciales e intente de nuevo "
} }
}, },
"password": { "password": {