feat(profile): add updateProfile method and enhance password validation in register form
This commit is contained in:
@@ -18,6 +18,14 @@ export interface RegisterPayload {
|
|||||||
password_confirmation: string;
|
password_confirmation: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UpdateProfilePayload {
|
||||||
|
nombre_apellido: string;
|
||||||
|
email: string;
|
||||||
|
dni?: string;
|
||||||
|
telefono?: string;
|
||||||
|
password?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface LoginResponse {
|
export interface LoginResponse {
|
||||||
message: string;
|
message: string;
|
||||||
token: string;
|
token: string;
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import {
|
|||||||
LoginPayload,
|
LoginPayload,
|
||||||
LoginResponse,
|
LoginResponse,
|
||||||
RegisterPayload,
|
RegisterPayload,
|
||||||
RegisterResponse
|
RegisterResponse,
|
||||||
|
UpdateProfilePayload
|
||||||
} from './auth.interfaces';
|
} from './auth.interfaces';
|
||||||
import { CookieService } from '../cookie/cookie.service';
|
import { CookieService } from '../cookie/cookie.service';
|
||||||
|
|
||||||
@@ -43,6 +44,12 @@ export class AuthService {
|
|||||||
return this.http.post<RegisterResponse>(`${environment.url}register`, payload);
|
return this.http.post<RegisterResponse>(`${environment.url}register`, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateProfile(payload: UpdateProfilePayload): Observable<AuthUser> {
|
||||||
|
return this.http.put<AuthUser>(`${environment.url}me`, payload).pipe(
|
||||||
|
tap((user) => this.userState.set(user))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
logout(): Observable<void> {
|
logout(): Observable<void> {
|
||||||
if (!this.tokenState()) {
|
if (!this.tokenState()) {
|
||||||
this.clearSession();
|
this.clearSession();
|
||||||
|
|||||||
@@ -55,7 +55,11 @@ export class RegisterPageComponent {
|
|||||||
'',
|
'',
|
||||||
[Validators.required, Validators.email, Validators.maxLength(TEXT_MAX_LENGTH)]
|
[Validators.required, Validators.email, Validators.maxLength(TEXT_MAX_LENGTH)]
|
||||||
],
|
],
|
||||||
password: ['', [Validators.required, Validators.minLength(PASSWORD_MIN_LENGTH)]],
|
password: ['', [
|
||||||
|
Validators.required,
|
||||||
|
Validators.minLength(PASSWORD_MIN_LENGTH),
|
||||||
|
Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[\W_]).+$/)
|
||||||
|
]],
|
||||||
password_confirmation: ['', [Validators.required]]
|
password_confirmation: ['', [Validators.required]]
|
||||||
}, {
|
}, {
|
||||||
validators: [passwordsMatchValidator]
|
validators: [passwordsMatchValidator]
|
||||||
@@ -142,6 +146,10 @@ export class RegisterPageComponent {
|
|||||||
return `Debe tener al menos ${PASSWORD_MIN_LENGTH} caracteres.`;
|
return `Debe tener al menos ${PASSWORD_MIN_LENGTH} caracteres.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (controlName === 'password' && control.hasError('pattern')) {
|
||||||
|
return 'Debe contener mayuscula, minuscula y un caracter especial.';
|
||||||
|
}
|
||||||
|
|
||||||
if (controlName === 'password_confirmation' && this.form.hasError('passwordMismatch')) {
|
if (controlName === 'password_confirmation' && this.form.hasError('passwordMismatch')) {
|
||||||
return 'Las contrasenas no coinciden.';
|
return 'Las contrasenas no coinciden.';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user