2015-05-09 19:00:14 +00:00
|
|
|
angular.module('SeHub')
|
2015-06-24 10:28:27 +00:00
|
|
|
.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.campusChecked = false;
|
|
|
|
$scope.createCampusClicked = false;
|
|
|
|
$scope.isEmpty = true; // if the academic email line is empty
|
|
|
|
$scope.jsonCreateCampus = {
|
|
|
|
"title": "Create Campus",
|
|
|
|
"email": "email_ending",
|
|
|
|
"avatar": "self.avatar.url"
|
2015-06-14 16:35:50 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 10:28:27 +00:00
|
|
|
$rootScope.seToken = $cookies['com.sehub.www'];
|
|
|
|
var token = $rootScope.seToken;
|
|
|
|
|
|
|
|
apiService.getUserByToken(token).success(function(data) // Get user token
|
2015-06-24 18:35:21 +00:00
|
|
|
{
|
|
|
|
$scope.user = data;
|
2015-06-24 10:28:27 +00:00
|
|
|
|
2015-06-24 18:35:21 +00:00
|
|
|
if (data.message == 'No User Found')
|
|
|
|
console.error("No User Found!");
|
|
|
|
console.log(data);
|
2015-06-24 10:28:27 +00:00
|
|
|
|
2015-06-24 18:35:21 +00:00
|
|
|
if ($scope.user.name === ";") {
|
|
|
|
$scope.user.name = "";
|
|
|
|
$scope.user.name = $scope.user.username;
|
|
|
|
$scope.userHasNoName = true;
|
|
|
|
}
|
2015-06-24 10:28:27 +00:00
|
|
|
|
2015-06-24 18:35:21 +00:00
|
|
|
apiService.getAllCampuses(token).success(function(data) // Get all the campuses
|
|
|
|
{
|
|
|
|
$scope.campuses = data;
|
|
|
|
}).error(function() {
|
|
|
|
// TODO
|
2015-06-24 10:28:27 +00:00
|
|
|
});
|
2015-06-24 18:35:21 +00:00
|
|
|
});
|
2015-06-24 10:28:27 +00:00
|
|
|
|
|
|
|
$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!!
|
|
|
|
}
|
|
|
|
};
|
2015-06-14 15:54:51 +00:00
|
|
|
};
|
2015-06-24 10:28:27 +00:00
|
|
|
|
2015-06-14 17:06:00 +00:00
|
|
|
};
|
2015-06-16 08:34:04 +00:00
|
|
|
|
2015-06-24 10:28:27 +00:00
|
|
|
$scope.submitClicked = function(ev) {
|
|
|
|
var emailValid = false;
|
2015-06-14 15:54:51 +00:00
|
|
|
|
2015-06-24 10:28:27 +00:00
|
|
|
if ($scope.user.AcMail != null) {
|
|
|
|
var fullMail = $scope.user.AcMail + $scope.campusObj.email_ending; // Holds the full academic email of the user
|
2015-06-17 19:38:07 +00:00
|
|
|
|
2015-06-24 10:28:27 +00:00
|
|
|
apiService.updateUser(token, $scope.user).success(function(data) {
|
2015-06-17 19:38:07 +00:00
|
|
|
|
2015-06-24 10:28:27 +00:00
|
|
|
}).error(function() {
|
|
|
|
// TODO Error
|
|
|
|
console.log("Error occured on updateUser");
|
|
|
|
});
|
2015-06-16 20:29:34 +00:00
|
|
|
|
2015-06-24 10:28:27 +00:00
|
|
|
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
|
2015-06-14 17:06:00 +00:00
|
|
|
{
|
2015-06-14 19:06:27 +00:00
|
|
|
$mdDialog.show($mdDialog.alert().title('Error - E-mail Verification').content('An error has occured in your e-mail address.')
|
2015-06-24 10:28:27 +00:00
|
|
|
.ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(ev));
|
|
|
|
};
|
2015-06-14 17:06:00 +00:00
|
|
|
};
|
2015-05-09 19:00:14 +00:00
|
|
|
|
2015-06-24 10:28:27 +00:00
|
|
|
$scope.createCampus = function(ev) {
|
2015-06-26 13:49:46 +00:00
|
|
|
$scope.createCampusClicked = !$scope.createCampusClicked;
|
2015-06-15 14:46:02 +00:00
|
|
|
|
2015-06-24 10:28:27 +00:00
|
|
|
if (!$scope.isLecturer) // "!isLecturer" Means => I Am Lecturer; if i am a lecturer (when pressing -> getting last data value before pressing)
|
2015-06-16 08:34:04 +00:00
|
|
|
{
|
2015-06-24 10:28:27 +00:00
|
|
|
if ($scope.user.campusMail != null) {
|
|
|
|
validateEmail($scope.user.campusMail); // Verify the email according to "xxx@name.suffix"
|
|
|
|
}
|
2015-06-16 08:34:04 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-24 10:28:27 +00:00
|
|
|
|
|
|
|
validateEmail = function(email) {
|
|
|
|
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
|
2015-06-16 17:24:09 +00:00
|
|
|
{
|
2015-06-24 10:28:27 +00:00
|
|
|
$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
|
2015-06-16 17:24:09 +00:00
|
|
|
{
|
2015-06-24 10:28:27 +00:00
|
|
|
console.log("Im good");
|
|
|
|
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));
|
|
|
|
});
|
|
|
|
}
|
2015-06-16 17:24:09 +00:00
|
|
|
}
|
2015-06-24 10:28:27 +00:00
|
|
|
}]);
|