From 51fa91d6019b5ba46ac63ed0288a6903178f1bfe Mon Sep 17 00:00:00 2001 From: Matan Bar Yosef Date: Tue, 16 Jun 2015 20:24:09 +0300 Subject: [PATCH] - email validation for lecturer in campus now working! --- templates/js/controllers/homeController.js | 1 - .../js/controllers/registerController.js | 84 +++++++++++++------ templates/views/register.html | 11 --- 3 files changed, 58 insertions(+), 38 deletions(-) diff --git a/templates/js/controllers/homeController.js b/templates/js/controllers/homeController.js index 976e68e..46395cb 100644 --- a/templates/js/controllers/homeController.js +++ b/templates/js/controllers/homeController.js @@ -6,5 +6,4 @@ angular.module('SeHub') { - }]); \ No newline at end of file diff --git a/templates/js/controllers/registerController.js b/templates/js/controllers/registerController.js index 706670b..346f731 100644 --- a/templates/js/controllers/registerController.js +++ b/templates/js/controllers/registerController.js @@ -76,37 +76,69 @@ angular.module('SeHub') }; - $scope.lecturer = function(ev) + $scope.createCampus = function(ev) { - console.log("inside"); $scope.createCampusClicked = true; - if(!$scope.isLecturer) // if i am a lecturer (when pressing -> getting last data value before pressing) = "!isLecturer" it means => I Am Lecturer + if(!$scope.isLecturer) // "!isLecturer" Means => I Am Lecturer; if i am a lecturer (when pressing -> getting last data value before pressing) { - // var jsonCreateCampus = - // { - // "title": "Create Campus", - // "email": "email_ending", - // "avatar": "self.avatar.url" - // } - console.log("YES lecturer " + $scope.jsonCreateCampus.title); - - if($scope.user.lecAcMail != null) + if($scope.user.campusSuffixMail != null) { - apiService.sendValidationMail($scope.user.seToken, $scope.user.lecAcMail).success(function(data) - { - console.log("DONE - 200"); - $mdDialog.show($mdDialog.alert().title('E-mail Verification').content('A verification e-mail has been sent to your email address.') - .ariaLabel('Email verification alert dialog').ok('Got it!').targetEvent(ev)); // Pop-up alert for e-mail verification - // TODO ADD delete cookies and redirect only after pressed 'Got it' - $cookieStore.remove("com.sehub.www"); // Removing the cookies - $window.location.href = 'http://se-hub.appspot.com'; // Reference to 'welcome' page - }).error(function() - { - $mdDialog.show($mdDialog.alert().title('Error - E-mail Verification').content('An error has occured in your e-mail address or in the campus name.') - .ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(ev)); - }); + validateEmail($scope.user.campusSuffixMail); } } - } + } + + validateEmail = function(email) // TODO ADD IT + { + var result = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; + + console.log("Email: " + email); + + if (!result.test(email)) + { + console.log(email + ", Error in email, should alert"); + alert('Please provide a valid e-mail address'); + } + + if(result.test(email)) + { + console.log("Im good"); + apiService.sendValidationMail($scope.user.seToken, email).success(function(data) + { + console.log("DONE - 200"); + $mdDialog.show($mdDialog.alert().title('E-mail Verification').content('A verification e-mail has been sent to your email address.') + .ariaLabel('Email verification alert dialog').ok('Got it!').targetEvent(email)); // Pop-up alert for e-mail verification + // TODO ADD delete cookies and redirect only after pressed 'Got it' + $cookieStore.remove("com.sehub.www"); // Removing the cookies + $window.location.href = 'http://se-hub.appspot.com'; // Reference to 'welcome' page + }).error(function() + { + $mdDialog.show($mdDialog.alert().title('Error - E-mail Verification').content('An error has occured in your e-mail address or in the campus name.') + .ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(email)); + }); + } + } + + // TODO FOR LATER - toast + // TODO FOR LATER + + // $scope.getPopWindowPosition = function() + // { + // return Object.keys($scope.toastPosition).filter(function(pos) + // { + // return $scope.toastPosition[pos]; + // }).join(' '); + // }; + + // $scope.toastPosition = + // { + // bottom: false, + // top: true, + // left: false, + // right: true + // }; + + // TODO FOR LATER + // TODO FOR LATER }]); diff --git a/templates/views/register.html b/templates/views/register.html index f835e8b..f25b61a 100644 --- a/templates/views/register.html +++ b/templates/views/register.html @@ -30,9 +30,6 @@ - @@ -51,7 +48,6 @@ -
@@ -79,13 +75,6 @@
- - \ No newline at end of file