2015-05-09 19:00:14 +00:00
|
|
|
angular.module('SeHub')
|
2015-06-15 08:37:21 +00:00
|
|
|
.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;
|
|
|
|
|
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-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
|
|
|
{
|
2015-06-16 20:29:34 +00:00
|
|
|
var emailValid = false;
|
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-16 20:29:34 +00:00
|
|
|
|
|
|
|
console.log("Mail: " + fullMail);
|
|
|
|
|
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.')
|
2015-06-15 08:37:21 +00:00
|
|
|
.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'
|
2015-06-15 08:37:21 +00:00
|
|
|
$cookieStore.remove("com.sehub.www"); // Removing the cookies
|
2015-06-15 16:12:54 +00:00
|
|
|
$window.location.href = 'http://se-hub.appspot.com'; // Reference to 'welcome' page
|
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-16 20:29:34 +00:00
|
|
|
}
|
|
|
|
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));
|
2015-06-14 17:06:00 +00:00
|
|
|
};
|
2015-06-14 16:31:16 +00:00
|
|
|
};
|
2015-05-09 19:00:14 +00:00
|
|
|
|
2015-06-16 17:24:09 +00:00
|
|
|
$scope.createCampus = function(ev)
|
2015-06-16 08:34:04 +00:00
|
|
|
{
|
|
|
|
$scope.createCampusClicked = true;
|
2015-06-15 14:46:02 +00:00
|
|
|
|
2015-06-16 17:24:09 +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-16 20:29:34 +00:00
|
|
|
if($scope.user.campusMail != null)
|
2015-06-16 08:34:04 +00:00
|
|
|
{
|
2015-06-16 20:29:34 +00:00
|
|
|
validateEmail($scope.user.campusMail); // Verify the email according to "xxx@name.suffix"
|
2015-06-16 08:34:04 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-16 17:24:09 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 20:29:34 +00:00
|
|
|
validateEmail = function(email)
|
2015-06-16 17:24:09 +00:00
|
|
|
{
|
|
|
|
var result = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
|
2015-06-16 20:29:34 +00:00
|
|
|
if (!result.test(email)) // TODO Fix when success to show mdDialog until 'Got it' clicked
|
2015-06-16 17:24:09 +00:00
|
|
|
{
|
|
|
|
console.log(email + ", Error in email, should alert");
|
2015-06-16 20:29:34 +00:00
|
|
|
// alert('Please provide a valid e-mail address');
|
|
|
|
$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));
|
2015-06-16 17:24:09 +00:00
|
|
|
}
|
2015-06-16 20:29:34 +00:00
|
|
|
if(result.test(email)) // TODO Fix when success to show mdDialog until 'Got it' clicked
|
2015-06-16 17:24:09 +00:00
|
|
|
{
|
|
|
|
console.log("Im good");
|
|
|
|
apiService.sendValidationMail($scope.user.seToken, 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-15 14:46:02 +00:00
|
|
|
}]);
|