se-hub/templates/js/controllers/registerController.js

73 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-05-09 19:00:14 +00:00
angular.module('SeHub')
.controller('registerController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function ($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope)
2015-06-14 19:06:27 +00:00
{
2015-05-09 19:00:14 +00:00
$scope.userHasNoName = false;
2015-06-14 15:54:51 +00:00
$scope.campusChecked = false;
$scope.isEmpty = true; // if the academic email line is empty
2015-06-14 16:35:50 +00:00
$rootScope.seToken = $cookies['com.sehub.www'];
var token = $rootScope.seToken;
apiService.getUserByToken(token).success(function(data) // Get user token
{
2015-06-14 16:35:50 +00:00
$scope.user = data;
2015-06-14 16:35:50 +00:00
if(data.message == 'No User Found')
console.error("No User Found!");
console.log(data);
2015-06-14 16:35:50 +00:00
2015-06-14 19:06:27 +00:00
if($scope.user.name === ";")
{
2015-06-14 16:35:50 +00:00
$scope.user.name = "";
$scope.user.name = $scope.user.username
$scope.userHasNoName = true;
}
2015-06-14 19:06:27 +00:00
apiService.getAllCampuses($scope.user.seToken).success(function(data) // Get all the campuses
{
$scope.campuses = data;
}).error(function()
{
// TODO
});
2015-06-14 16:35:50 +00:00
});
2015-06-14 15:54:51 +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];
2015-06-14 16:35:50 +00:00
console.log($scope.campusObj); // TODO REMOVE!!
2015-06-14 15:54:51 +00:00
}
};
};
2015-06-14 16:31:16 +00:00
};
2015-06-14 15:54:51 +00:00
2015-06-14 19:06:27 +00:00
$scope.submitClicked = function(ev)
2015-06-14 15:54:51 +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-14 19:06:27 +00:00
apiService.sendValidationMail($scope.user.seToken, fullMail).success(function(data)
{
2015-06-14 19:06:27 +00:00
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
$cookieStore.remove("com.sehub.www"); // Removing the cookies
$window.location.href = 'http://se-hub.appspot.com';
}).error(function()
{
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.')
.ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(ev));
});
};
2015-06-14 16:31:16 +00:00
};
2015-06-14 19:06:27 +00:00
}]);
2015-05-09 19:00:14 +00:00
2015-06-09 17:53:57 +00:00