diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index f2e9946..974fdff 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -64,9 +64,22 @@ export class AuthService { await this.router.navigate(['/main/menu']); } - async register(username: string, password: string): Promise { + async register( + username: string, + password: string, + email: string, + tel: string, + description: string | null = null + ): Promise { await firstValueFrom( - this.http.post('/API/users/register', { username, password } as RegisterRequest) + this.http.post('/API/users', { + username, + password, + email, + tel, + description, + profilePicture: null + }) ); await this.login(username, password); diff --git a/src/app/pages/register-form/register-form.component.html b/src/app/pages/register-form/register-form.component.html index a15ad56..b7aae68 100644 --- a/src/app/pages/register-form/register-form.component.html +++ b/src/app/pages/register-form/register-form.component.html @@ -16,6 +16,14 @@ + + + + + + + + @@ -24,7 +32,8 @@ -

+

Les mots de passe ne correspondent pas.

diff --git a/src/app/pages/register-form/register-form.component.ts b/src/app/pages/register-form/register-form.component.ts index 0ae45c0..087f3dc 100644 --- a/src/app/pages/register-form/register-form.component.ts +++ b/src/app/pages/register-form/register-form.component.ts @@ -1,11 +1,9 @@ import { Component, inject } from '@angular/core'; -import { - IonButton, IonContent, IonInput, IonItem -} from "@ionic/angular/standalone"; +import { IonButton, IonContent, IonInput, IonItem } from "@ionic/angular/standalone"; import { Router } from "@angular/router"; import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms"; import { CommonModule } from "@angular/common"; -import {AuthService} from "../../core/auth/auth.service"; +import { AuthService } from "../../core/auth/auth.service"; @Component({ selector: 'app-register-form', @@ -22,14 +20,17 @@ export class RegisterFormComponent { isLoading = false; registerForm = this.fb.group({ - username: ['', [Validators.required, Validators.maxLength(50)]], - password: ['', [Validators.required, Validators.minLength(12), Validators.maxLength(50)]], - confirmPassword: ['', [Validators.required]] + username: ['', [Validators.required, Validators.maxLength(50)]], + email: ['', [Validators.required, Validators.email, Validators.maxLength(70)]], + tel: ['', [Validators.required, Validators.minLength(10), Validators.maxLength(10)]], + password: ['', [Validators.required, Validators.minLength(12), Validators.maxLength(50)]], + confirmPassword: ['', [Validators.required]], + description: ['', [Validators.maxLength(200)]], }, { validators: this.passwordMatchValidator }); passwordMatchValidator(form: any) { const password = form.get('password')?.value; - const confirm = form.get('confirmPassword')?.value; + const confirm = form.get('confirmPassword')?.value; return password === confirm ? null : { passwordMismatch: true }; } @@ -43,7 +44,10 @@ export class RegisterFormComponent { try { await this.authService.register( this.registerForm.value.username!, - this.registerForm.value.password! + this.registerForm.value.password!, + this.registerForm.value.email!, + this.registerForm.value.tel!, + this.registerForm.value.description ?? null, ); } catch (err: any) { if (err.status === 409) { @@ -54,6 +58,13 @@ export class RegisterFormComponent { } finally { this.isLoading = false; } + } else { + Object.values(this.registerForm.controls).forEach(control => { + if (control.invalid) { + control.markAsDirty(); + control.updateValueAndValidity({ onlySelf: true }); + } + }); } } } \ No newline at end of file