diff --git a/src/app/core/services/auth/auth.interfaces.ts b/src/app/core/services/auth/auth.interfaces.ts index 396521c..80ae087 100644 --- a/src/app/core/services/auth/auth.interfaces.ts +++ b/src/app/core/services/auth/auth.interfaces.ts @@ -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; diff --git a/src/app/core/services/auth/auth.service.ts b/src/app/core/services/auth/auth.service.ts index 78b195a..94c7fb9 100644 --- a/src/app/core/services/auth/auth.service.ts +++ b/src/app/core/services/auth/auth.service.ts @@ -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(`${environment.url}register`, payload); } + updateProfile(payload: UpdateProfilePayload): Observable { + return this.http.put(`${environment.url}me`, payload).pipe( + tap((user) => this.userState.set(user)) + ); + } + logout(): Observable { if (!this.tokenState()) { this.clearSession(); diff --git a/src/app/features/store/pages/register-page/register-page.component.ts b/src/app/features/store/pages/register-page/register-page.component.ts index dbf7236..196a0d3 100644 --- a/src/app/features/store/pages/register-page/register-page.component.ts +++ b/src/app/features/store/pages/register-page/register-page.component.ts @@ -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.'; }