feat(profile): add updateProfile method and enhance password validation in register form

This commit is contained in:
2026-07-08 12:06:36 -03:00
parent b016569b10
commit 7507580c2c
3 changed files with 25 additions and 2 deletions

View File

@@ -18,6 +18,14 @@ export interface RegisterPayload {
password_confirmation: string;
}
export interface UpdateProfilePayload {
nombre_apellido: string;
email: string;
dni?: string;
telefono?: string;
password?: string;
}
export interface LoginResponse {
message: string;
token: string;

View File

@@ -9,7 +9,8 @@ import {
LoginPayload,
LoginResponse,
RegisterPayload,
RegisterResponse
RegisterResponse,
UpdateProfilePayload
} from './auth.interfaces';
import { CookieService } from '../cookie/cookie.service';
@@ -43,6 +44,12 @@ export class AuthService {
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> {
if (!this.tokenState()) {
this.clearSession();

View File

@@ -55,7 +55,11 @@ export class RegisterPageComponent {
'',
[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]]
}, {
validators: [passwordsMatchValidator]
@@ -142,6 +146,10 @@ export class RegisterPageComponent {
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')) {
return 'Las contrasenas no coinciden.';
}