Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

#597: added email validator to reset form, show hint if the email isn… #637

Merged
merged 5 commits into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/webFrontend/src/app/auth/reset/reset.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {MatSnackBar} from '@angular/material';
import {ActivatedRoute, Router} from '@angular/router';
import {isNullOrUndefined} from 'util';
import {TitleService} from '../../shared/services/title.service';
import {emailValidator} from '../../shared/validators/validators';

@Component({
templateUrl: './reset.component.html',
Expand Down Expand Up @@ -43,6 +44,11 @@ export class ResetComponent implements OnInit {
}

requestReset() {
if (!this.resetForm.valid) {
this.snackBar.open('The email address you entered is not valid.', 'Dismiss');
return;
}

this.showProgress.toggleLoadingGlobal(true);
this.loading = true;
this.authenticationService.requestReset(this.resetForm.value.email.replace(/\s/g, '').toLowerCase())
Expand Down Expand Up @@ -80,7 +86,7 @@ export class ResetComponent implements OnInit {
this.resetForm = this.formBuilder.group({});
} else {
this.resetForm = this.formBuilder.group({
email: ['', Validators.required]
email: ['', emailValidator ]
});
}
}
Expand Down
20 changes: 19 additions & 1 deletion app/webFrontend/src/app/shared/validators/validators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {FormGroup} from '@angular/forms';
import {FormControl, FormGroup} from '@angular/forms';

export function matchPasswords(passwordKey: string, confirmPasswordKey: string) {
return (group: FormGroup): { [key: string]: any } => {
Expand All @@ -12,3 +12,21 @@ export function matchPasswords(passwordKey: string, confirmPasswordKey: string)
}
};
}

/**
* A custom email validator which, in comparison to the default angular email validator,
* also checks if the email address has a top-level domain.
*
* @param {FormControl} formControl
* @returns {{emailValidator: {valid: boolean}}}
*/
export function emailValidator(formControl: FormControl) {
// Email Regex from: http://emailregex.com/
// tslint:disable-next-line:max-line-length
const EMAIL_REGEX = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return EMAIL_REGEX.test(formControl.value) ? null : {
emailValidator: {
valid: false
}
};
}