Move email validation to library

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@54440 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
sofia.baltzi 2018-12-17 15:17:58 +00:00
parent b114f0d25a
commit 68b73fbe1e
1 changed files with 24 additions and 22 deletions

View File

@ -13,6 +13,7 @@ import {EnvProperties} from '../../../openaire
import {CommunityInfo} from '../../../openaireLibrary/connect/community/communityInfo';
import {Email} from "../../../openaireLibrary/utils/email/email";
import {Composer} from "../../../openaireLibrary/utils/email/composer";
import {Validator} from "../../../openaireLibrary/utils/email/validator";
import {Session} from '../../../openaireLibrary/login/utils/helper.class';
import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class';
@ -160,7 +161,8 @@ export class CommunityEditFormComponent implements OnInit{
// TODO delete after testing
console.log(community);
if (!this.hasValidEmail(community) || !this.hasFilled(community["name"])) {
if (!Validator.hasValidEmails(community['managers']) || !this.hasFilled(community["name"])) {
// if (!this.hasValidEmail(community) || !this.hasFilled(community["name"])) {
this._router.navigate(['/community-edit-form'], {queryParams: { "communityId": this.communityId}});
} else {
var newManagers = this.getNewManagers();
@ -301,27 +303,27 @@ export class CommunityEditFormComponent implements OnInit{
return false;
}
private hasValidEmail(data: any): boolean {
let length = data['managers'].length;
for(let i = 0; i < length; i++) {
if (!this.emailValidator(data['managers'][i])){
// TODO remove console message after final testing
console.log("INVALID EMAIL");
return false;
}
}
// TODO remove console message after final testing
console.log("ALL EMAILS ARE VALID");
return true;
}
private emailValidator(email : any): boolean {
if (email.match("^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"))
return true;
else
return false;
}
// private hasValidEmail(data: any): boolean {
// let length = data['managers'].length;
//
// for(let i = 0; i < length; i++) {
// if (!this.emailValidator(data['managers'][i])){
// // TODO remove console message after final testing
// console.log("INVALID EMAIL");
// return false;
// }
// }
// // TODO remove console message after final testing
// console.log("ALL EMAILS ARE VALID");
// return true;
// }
//
// private emailValidator(email : any): boolean {
// if (email.match("^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"))
// return true;
// else
// return false;
// }
private change() {
this.hasChanged = true;