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