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

113 lines
4 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;
2015-06-16 08:34:04 +00:00
$scope.createCampusClicked = false;
2015-06-14 15:54:51 +00:00
$scope.isEmpty = true; // if the academic email line is empty
2015-06-16 08:34:04 +00:00
$scope.jsonCreateCampus =
{
"title": "Create Campus",
"email": "email_ending",
"avatar": "self.avatar.url"
}
2015-06-14 15:54:51 +00:00
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-16 08:34:04 +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
2015-06-16 08:34:04 +00:00
// 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()
{
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-05-09 19:00:14 +00:00
2015-06-09 17:53:57 +00:00
2015-06-16 08:34:04 +00:00
$scope.lecturer = function(ev)
{
console.log("inside");
$scope.createCampusClicked = true;
2015-06-15 14:46:02 +00:00
2015-06-16 08:34:04 +00:00
if(!$scope.isLecturer) // if i am a lecturer (when pressing -> getting last data value before pressing) = "!isLecturer" it means => I Am Lecturer
{
// var jsonCreateCampus =
// {
// "title": "Create Campus",
// "email": "email_ending",
// "avatar": "self.avatar.url"
// }
console.log("YES lecturer " + $scope.jsonCreateCampus.title);
2015-06-15 14:46:02 +00:00
2015-06-16 08:34:04 +00:00
if($scope.user.lecAcMail != 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));
});
}
}
}
2015-06-15 14:46:02 +00:00
}]);