gerer le succes/echec incription si user avec login existant
continuous-integration/drone/push Build is failing Details

pull/14/head
Hugo PRADIER 1 year ago
parent f6d28150c9
commit d475fba1a8

@ -6,3 +6,13 @@
.form-field {
width: 100%;
}
.success-message {
color: green;
margin-top: 20px;
}
.error-message {
color: red;
margin-top: 20px;
}

@ -49,4 +49,12 @@
[disabled]="email.invalid || login.invalid || password.invalid">
Créer un compte
</button>
<!-- Message de retour de l'inscription -->
<div *ngIf="successRegister" class="success-message">
{{ successRegister }}
</div>
<div *ngIf="errorRegister" class="error-message">
{{ errorRegister }}
</div>
</div>

@ -42,6 +42,9 @@ export class RegisterComponent {
errorMessage = '';
successRegister = '';
errorRegister = '';
constructor(private userService: UserService) {
merge(this.email.statusChanges, this.email.valueChanges)
.pipe(takeUntilDestroyed())
@ -69,6 +72,17 @@ export class RegisterComponent {
password: this.password.value,
},
};
this.userService.postUser(form);
// this.userService.postUser(form);
this.userService.postUser(form).subscribe((response) => {
console.log('response :', response);
if ((response as any).success) {
this.successRegister = 'Votre compte a été créé avec succès.';
this.errorRegister = '';
} else {
this.errorRegister =
"L'inscription a échoué : un compte avec ce login existe déjà.";
this.successRegister = '';
}
});
}
}

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { User } from '../models/user.model';
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { NgForm } from '@angular/forms';
@ -18,12 +18,17 @@ export class UserService {
return this.http.get(`${this.API_URL}/Users`);
}
postUser(form: NgForm): void {
postUser(form: NgForm): Observable<HttpResponse<Response>> {
let body = {
login: form.value.login,
password: form.value.password,
permissions: 0,
};
this.http.post<any>(`${this.API_URL}/users`, body).subscribe();
return this.http.post<any>(`${this.API_URL}/users`, body);
}
}
type Response = {
success: boolean;
};

Loading…
Cancel
Save