Skip to content
Snippets Groups Projects
Commit 02f75f2f authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

fix(auth): add regex for password check + add email already in use msg

parent a1606311
No related branches found
No related tags found
3 merge requests!68Recette,!67Dev,!38Feat/auth
......@@ -30,7 +30,7 @@
/>
<div *ngIf="submitted && f.password.errors" class="invalid-feedback">
<div *ngIf="f.password.errors.required">Le mot de passe est obligatoire</div>
<div *ngIf="f.password.errors.minlength">
<div *ngIf="f.password.errors.pattern">
Le mot de passe doit avoir au minimun 8 caractères, une majuscule, une minuscule, un chiffre et un
caractère spécial.
</div>
......@@ -46,10 +46,12 @@
[ngClass]="{ 'is-invalid': submitted && f.confirmPassword.errors }"
/>
<div *ngIf="submitted && f.confirmPassword.errors" class="invalid-feedback">
<div *ngIf="f.confirmPassword.errors.required">Le mot de passe est obligatoire</div>
<div *ngIf="f.confirmPassword.errors.required">La confirmation du mot de passe est obligatoire</div>
<div *ngIf="f.confirmPassword.errors.mustMatch">Les mot de passe ne sont pas les mêmes</div>
</div>
</div>
<div *ngIf="userAlreadyExist">Cette addresse mail est déjà utilisée</div>
<div class="form-group">
<button [disabled]="loading" class="btn btn-primary">
<span *ngIf="loading" class="spinner-border spinner-border-sm mr-1"></span>
......
......@@ -14,6 +14,7 @@ export class SignInModalComponent implements OnInit {
public loading = false;
public submitted = false;
public success = false;
public userAlreadyExist = false;
constructor(private formBuilder: FormBuilder, private authService: AuthService) {}
......@@ -24,7 +25,10 @@ export class SignInModalComponent implements OnInit {
this.form = this.formBuilder.group(
{
email: ['', Validators.required],
password: ['', [Validators.required, Validators.minLength(8)]],
password: [
'',
[Validators.required, Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})/)],
],
confirmPassword: ['', [Validators.required, Validators.minLength(8)]],
},
{ validator: MustMatch('password', 'confirmPassword') }
......@@ -53,11 +57,14 @@ export class SignInModalComponent implements OnInit {
.register(this.form.value)
.pipe(first())
.subscribe(
(data) => {
() => {
this.success = true;
},
(error) => {
this.loading = false;
if (error.error.statusCode === 400) {
this.userAlreadyExist = true;
}
}
);
}
......
......@@ -6,11 +6,6 @@ export function MustMatch(controlName: string, matchingControlName: string): any
const control = formGroup.controls[controlName];
const matchingControl = formGroup.controls[matchingControlName];
if (matchingControl.errors && !matchingControl.errors.mustMatch) {
// return if another validator has already found an error on the matchingControl
return;
}
// set error on matchingControl if validation fails
if (control.value !== matchingControl.value) {
matchingControl.setErrors({ mustMatch: true });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment