Fixing Register POPUP

This commit is contained in:
Sagi Dayan 2015-06-24 13:28:27 +03:00
parent 522a71d9c4
commit 5f53e3ff85

View file

@ -1,141 +1,126 @@
angular.module('SeHub') angular.module('SeHub')
.controller('registerController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function ($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope) .controller('registerController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService, $rootScope) {
{ $scope.userHasNoName = false;
$scope.userHasNoName = false; $scope.campusChecked = false;
$scope.campusChecked = false; $scope.createCampusClicked = false;
$scope.createCampusClicked = false; $scope.isEmpty = true; // if the academic email line is empty
$scope.isEmpty = true; // if the academic email line is empty $scope.jsonCreateCampus = {
$scope.jsonCreateCampus = "title": "Create Campus",
{ "email": "email_ending",
"title": "Create Campus", "avatar": "self.avatar.url"
"email": "email_ending",
"avatar": "self.avatar.url"
}
$rootScope.seToken = $cookies['com.sehub.www'];
var token = $rootScope.seToken;
apiService.getUserByToken(token).success(function(data) // Get user token
{
$scope.user = data;
if(data.message == 'No User Found')
console.error("No User Found!");
console.log(data);
if($scope.user.name === ";")
{
$scope.user.name = "";
$scope.user.name = $scope.user.username;
$scope.userHasNoName = true;
} }
apiService.getAllCampuses(token).success(function(data) // Get all the campuses $rootScope.seToken = $cookies['com.sehub.www'];
{ var token = $rootScope.seToken;
$scope.campuses = data;
}).error(function()
{
// TODO
});
});
$scope.dropdownClicked = function() apiService.getUserByToken(token).success(function(data) // Get user token
{ {
if($scope.campus){ $scope.user = data;
$scope.campusChecked = true;
$scope.campusObj = null; if (data.message == 'No User Found')
for (var i = $scope.campuses.length - 1; i >= 0; i--) { console.error("No User Found!");
if($scope.campuses[i].title == $scope.campus){ console.log(data);
$scope.campusObj = $scope.campuses[i];
console.log($scope.campusObj); // TODO REMOVE!! if ($scope.user.name === ";") {
$scope.user.name = "";
$scope.user.name = $scope.user.username;
$scope.userHasNoName = true;
} }
apiService.getAllCampuses(token).success(function(data) // Get all the campuses
{
$scope.campuses = data;
}).error(function() {
// TODO
});
});
$scope.dropdownClicked = function() {
if ($scope.campus) {
$scope.campusChecked = true;
$scope.campusObj = null;
for (var i = $scope.campuses.length - 1; i >= 0; i--) {
if ($scope.campuses[i].title == $scope.campus) {
$scope.campusObj = $scope.campuses[i];
console.log($scope.campusObj); // TODO REMOVE!!
}
};
};
};
$scope.submitClicked = function(ev) {
var emailValid = false;
if ($scope.user.AcMail != null) {
var fullMail = $scope.user.AcMail + $scope.campusObj.email_ending; // Holds the full academic email of the user
apiService.updateUser(token, $scope.user).success(function(data) {
}).error(function() {
// TODO Error
console.log("Error occured on updateUser");
});
console.log("Mail: " + fullMail);
apiService.sendValidationMail(token, fullMail).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))
.then(function() {
// 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
}); // Pop-up alert for e-mail verification
}).error(function() {
$mdDialog.show($mdDialog.alert().title('Error - E-mail Verification').content('An error has occured in your e-mail address.')
.ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(ev));
});
} else // TODO Fix when success to show mdDialog until 'Got it' clicked
{
$mdDialog.show($mdDialog.alert().title('Error - E-mail Verification').content('An error has occured in your e-mail address.')
.ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(ev));
}; };
}; };
}; $scope.createCampus = function(ev) {
$scope.createCampusClicked = true;
$scope.submitClicked = function(ev) if (!$scope.isLecturer) // "!isLecturer" Means => I Am Lecturer; if i am a lecturer (when pressing -> getting last data value before pressing)
{
var emailValid = false;
var jsonUpdateUser =
{
"lecturerStat": "$scope.user.isLecturer",
"campName": "$scope.campusName"
}
if($scope.user.AcMail != null)
{
var fullMail = $scope.user.AcMail + $scope.campusObj.email_ending; // Holds the full academic email of the user
apiService.updateUser($scope.user.seToken, jsonUpdateUser).success(function(data)
{ {
if ($scope.user.campusMail != null) {
}).error(function() validateEmail($scope.user.campusMail); // Verify the email according to "xxx@name.suffix"
{ }
// TODO Error
console.log("Error occured on updateUser");
});
console.log("Mail: " + fullMail);
apiService.sendValidationMail(token, fullMail).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.')
.ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(ev));
});
}
else // TODO Fix when success to show mdDialog until 'Got it' clicked
{
$mdDialog.show($mdDialog.alert().title('Error - E-mail Verification').content('An error has occured in your e-mail address.')
.ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(ev));
};
};
$scope.createCampus = function(ev)
{
$scope.createCampusClicked = true;
if(!$scope.isLecturer) // "!isLecturer" Means => I Am Lecturer; if i am a lecturer (when pressing -> getting last data value before pressing)
{
if($scope.user.campusMail != null)
{
validateEmail($scope.user.campusMail); // Verify the email according to "xxx@name.suffix"
} }
} }
}
validateEmail = function(email) validateEmail = function(email) {
{ var result = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
var result = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; if (!result.test(email)) // TODO Fix when success to show mdDialog until 'Got it' clicked
if (!result.test(email)) // TODO Fix when success to show mdDialog until 'Got it' clicked
{
$mdDialog.show($mdDialog.alert().title('Error - E-mail Verification').content('An error has occured in your e-mail address.')
.ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(email));
}
if(result.test(email)) // TODO Fix when success to show mdDialog until 'Got it' clicked
{
console.log("Im good");
apiService.sendValidationMail(token, email).success(function(data)
{ {
console.log("DONE - 200"); $mdDialog.show($mdDialog.alert().title('Error - E-mail Verification').content('An error has occured in your e-mail address.')
$mdDialog.show($mdDialog.alert().title('E-mail Verification').content('A verification e-mail has been sent to your email address.') .ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(email));
.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' if (result.test(email)) // TODO Fix when success to show mdDialog until 'Got it' clicked
$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.') console.log("Im good");
.ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(email)); apiService.sendValidationMail(token, 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));
});
}
} }
} }]);
}]);