diff --git a/src/app/components/home/_dialogs/register/register.component.ts b/src/app/components/home/_dialogs/register/register.component.ts index fb58693558c793ab18ede34cc6bc71806cd80361..72bd99337c51aa68f8fadc5b6ddd9ae3e2f57ec7 100644 --- a/src/app/components/home/_dialogs/register/register.component.ts +++ b/src/app/components/home/_dialogs/register/register.component.ts @@ -29,6 +29,23 @@ function validatePassword(password1: FormControl) { }; } +function validateEmail(email1: FormControl) { + return (formControl: FormControl) => { + const email1Value = email1.value; + const email2Value = formControl.value; + + if (email1Value !== email2Value) { + return { + emailIsEqual: { + isEqual: false + } + }; + } else { + return null; + } + }; +} + @Component({ selector: 'app-register', templateUrl: './register.component.html', @@ -37,6 +54,7 @@ function validatePassword(password1: FormControl) { export class RegisterComponent implements OnInit { usernameFormControl = new FormControl('', [Validators.required, Validators.email]); + username2FormControl = new FormControl('', [Validators.required, validateEmail(this.usernameFormControl)]); password1FormControl = new FormControl('', [Validators.required]); password2FormControl = new FormControl('', [Validators.required, validatePassword(this.password1FormControl)]); @@ -58,13 +76,14 @@ export class RegisterComponent implements OnInit { register(username: string, password: string): void { if (!this.usernameFormControl.hasError('required') && !this.usernameFormControl.hasError('email') && + !this.username2FormControl.hasError('required') && !this.username2FormControl.hasError('emailIsEqual') && !this.password1FormControl.hasError('required') && !this.password2FormControl.hasError('required') && !this.password2FormControl.hasError('passwordIsEqual')) { this.authenticationService.register(username, password).subscribe(() => { this.translationService.get('register.register-successful').subscribe(message => { this.notificationService.show(message); }); - this.dialogRef.close({username: username, password: password}); + this.dialogRef.close({ username: username, password: password }); }); } else { this.translationService.get('register.register-unsuccessful').subscribe(message => {