2015-05-09 19:00:14 +00:00
|
|
|
angular.module('SeHub')
|
2015-06-14 19:06:27 +00:00
|
|
|
.controller('registerController', ['$scope', '$cookies', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function ($scope, $cookies, $location, $mdToast, $mdDialog, apiService ,$rootScope)
|
|
|
|
{
|
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;
|
|
|
|
|
2015-06-14 17:22:00 +00:00
|
|
|
apiService.getUserByToken(token).success(function(data) // Get user token
|
|
|
|
{
|
2015-06-14 16:35:50 +00:00
|
|
|
$scope.user = data;
|
2015-06-14 17:06:00 +00:00
|
|
|
|
2015-06-14 16:35:50 +00:00
|
|
|
if(data.message == 'No User Found')
|
|
|
|
console.error("No User Found!");
|
2015-06-14 17:06:00 +00:00
|
|
|
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 17:06:00 +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
|
|
|
{
|
2015-06-14 17:06:00 +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 17:06:00 +00:00
|
|
|
{
|
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));
|
|
|
|
// TODO - ADD DELETE COOKIES
|
|
|
|
$cookies.remove("com.sehub.www");
|
|
|
|
// $location.path("templates/views/home.html"); // Redirecting to home page // TODO REMOVE REMOVE!!
|
2015-06-14 17:06:00 +00:00
|
|
|
}).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 17:06:00 +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
|
|
|
// TODO FOR LATER
|
|
|
|
// 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
|
|
|
|
};
|
2015-06-14 15:54:51 +00:00
|
|
|
|
2015-06-14 19:06:27 +00:00
|
|
|
// TODO FOR LATER
|
|
|
|
// TODO FOR LATER
|
2015-06-14 15:54:51 +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
|
|
|
|