Compare commits

...

2 Commits

Author SHA1 Message Date
gokhoal dcb715703e Merge remote-tracking branch 'origin/develop' into develop 2026-06-10 15:58:50 +02:00
gokhoal e5044c8940 nouveau register 2026-06-10 15:58:43 +02:00
3 changed files with 45 additions and 12 deletions
+15 -2
View File
@@ -64,9 +64,22 @@ export class AuthService {
await this.router.navigate(['/main/menu']);
}
async register(username: string, password: string): Promise<void> {
async register(
username: string,
password: string,
email: string,
tel: string,
description: string | null = null
): Promise<void> {
await firstValueFrom(
this.http.post<void>('/API/users/register', { username, password } as RegisterRequest)
this.http.post<void>('/API/users', {
username,
password,
email,
tel,
description,
profilePicture: null
})
);
await this.login(username, password);
@@ -16,6 +16,14 @@
<ion-input placeholder="Nom d'utilisateur..." formControlName="username"></ion-input>
</ion-item>
<ion-item lines="none" class="input">
<ion-input type="email" placeholder="Email..." formControlName="email"></ion-input>
</ion-item>
<ion-item lines="none" class="input">
<ion-input type="tel" placeholder="Téléphone (10 chiffres)..." formControlName="tel"></ion-input>
</ion-item>
<ion-item lines="none" class="input">
<ion-input type="password" placeholder="Mot de passe..." formControlName="password"></ion-input>
</ion-item>
@@ -24,7 +32,8 @@
<ion-input type="password" placeholder="Confirmez votre mot de passe..." formControlName="confirmPassword"></ion-input>
</ion-item>
<p *ngIf="registerForm.hasError('passwordMismatch')" style="color:#d97070; font-size:13px; text-align:center; margin:0;">
<p *ngIf="registerForm.hasError('passwordMismatch')"
style="color:#d97070; font-size:13px; text-align:center; margin:0;">
Les mots de passe ne correspondent pas.
</p>
@@ -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',
@@ -23,8 +21,11 @@ export class RegisterFormComponent {
registerForm = this.fb.group({
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]]
confirmPassword: ['', [Validators.required]],
description: ['', [Validators.maxLength(200)]],
}, { validators: this.passwordMatchValidator });
passwordMatchValidator(form: any) {
@@ -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 });
}
});
}
}
}