nouveau register
This commit is contained in:
@@ -64,9 +64,22 @@ export class AuthService {
|
|||||||
await this.router.navigate(['/main/menu']);
|
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(
|
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);
|
await this.login(username, password);
|
||||||
|
|||||||
@@ -16,6 +16,14 @@
|
|||||||
<ion-input placeholder="Nom d'utilisateur..." formControlName="username"></ion-input>
|
<ion-input placeholder="Nom d'utilisateur..." formControlName="username"></ion-input>
|
||||||
</ion-item>
|
</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-item lines="none" class="input">
|
||||||
<ion-input type="password" placeholder="Mot de passe..." formControlName="password"></ion-input>
|
<ion-input type="password" placeholder="Mot de passe..." formControlName="password"></ion-input>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
@@ -24,7 +32,8 @@
|
|||||||
<ion-input type="password" placeholder="Confirmez votre mot de passe..." formControlName="confirmPassword"></ion-input>
|
<ion-input type="password" placeholder="Confirmez votre mot de passe..." formControlName="confirmPassword"></ion-input>
|
||||||
</ion-item>
|
</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.
|
Les mots de passe ne correspondent pas.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import { Component, inject } from '@angular/core';
|
import { Component, inject } from '@angular/core';
|
||||||
import {
|
import { IonButton, IonContent, IonInput, IonItem } from "@ionic/angular/standalone";
|
||||||
IonButton, IonContent, IonInput, IonItem
|
|
||||||
} from "@ionic/angular/standalone";
|
|
||||||
import { Router } from "@angular/router";
|
import { Router } from "@angular/router";
|
||||||
import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms";
|
import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms";
|
||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import {AuthService} from "../../core/auth/auth.service";
|
import { AuthService } from "../../core/auth/auth.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-register-form',
|
selector: 'app-register-form',
|
||||||
@@ -22,14 +20,17 @@ export class RegisterFormComponent {
|
|||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
|
||||||
registerForm = this.fb.group({
|
registerForm = this.fb.group({
|
||||||
username: ['', [Validators.required, Validators.maxLength(50)]],
|
username: ['', [Validators.required, Validators.maxLength(50)]],
|
||||||
password: ['', [Validators.required, Validators.minLength(12), Validators.maxLength(50)]],
|
email: ['', [Validators.required, Validators.email, Validators.maxLength(70)]],
|
||||||
confirmPassword: ['', [Validators.required]]
|
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 });
|
}, { validators: this.passwordMatchValidator });
|
||||||
|
|
||||||
passwordMatchValidator(form: any) {
|
passwordMatchValidator(form: any) {
|
||||||
const password = form.get('password')?.value;
|
const password = form.get('password')?.value;
|
||||||
const confirm = form.get('confirmPassword')?.value;
|
const confirm = form.get('confirmPassword')?.value;
|
||||||
return password === confirm ? null : { passwordMismatch: true };
|
return password === confirm ? null : { passwordMismatch: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +44,10 @@ export class RegisterFormComponent {
|
|||||||
try {
|
try {
|
||||||
await this.authService.register(
|
await this.authService.register(
|
||||||
this.registerForm.value.username!,
|
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) {
|
} catch (err: any) {
|
||||||
if (err.status === 409) {
|
if (err.status === 409) {
|
||||||
@@ -54,6 +58,13 @@ export class RegisterFormComponent {
|
|||||||
} finally {
|
} finally {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Object.values(this.registerForm.controls).forEach(control => {
|
||||||
|
if (control.invalid) {
|
||||||
|
control.markAsDirty();
|
||||||
|
control.updateValueAndValidity({ onlySelf: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user