diff --git a/SE_API/API.py b/SE_API/API.py index 4779525..f83e020 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -20,9 +20,10 @@ from models.Course import Course from models.Project import Project from models.Campus import Campus -#Validation Utils Libs +# All API from SE_API.Validation_Utils import * from SE_API.Respones_Utils import * +from SE_API.Email_Utils import * from SE_API.UserRoutes import user_routes from SE_API.CampusRoutes import campus_routes diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index 43afbf1..e17bc44 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -143,4 +143,4 @@ def get_campuses(token): @campus_routes.route('/api/campuses/help') def documentation(): - return auto.html() \ No newline at end of file + return auto.html() diff --git a/SE_API/Email_Utils.py b/SE_API/Email_Utils.py new file mode 100644 index 0000000..683f7e8 --- /dev/null +++ b/SE_API/Email_Utils.py @@ -0,0 +1,127 @@ +__author__ = 'sagi' + + +from google.appengine.api import mail + + +def send_validation_email(token, email, name): + emailSuffix = str(email).split('@')[1] + message = mail.EmailMessage(sender="SE-Hub Support ", + subject="SE-Hub Activate Account") + + message.to = email + + message.body = """ + Dear """+name+""": + + To Activate your SE-Hub Account please click on the link below:
+ http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+""" + to get access to your Campus :) + + Please let us know if you have any questions. + + SE-Hub (c) 2015 niptop Team. + """ + + message.html = """ + +
+
+ + +
+
+
+

Hey """+name+"""- Just one More Step...

+

Dear """+name+""":

+ + To Activate your SE-Hub Account please click on the link below:
+ http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+""" + + to access you virtual class. +
+

+ Please let us know if you have any questions. +
+ SE-Hub (c) 2015 niptop Team. + + + """ + + message.send() + +def send_create_campus_request(email, name, campus_name): + message = mail.EmailMessage(sender="SE-Hub Support ", + subject="SE-Hub: "+campus_name+" Is Being Evaluated") + + message.to = email + + message.body = """ + Dear """+name+""": + + Thank You For Choosing SE-Hub! + Your Request for creating a new Campus named """+campus_name + """ + is Being Evaluated. + You Will Receive an e-mail When We finish the process
+ + Please let us know if you have any questions. + + SE-Hub (c) 2015 niptop Team. + """ + + message.html = """ + +
+
+ + +
+
+
+

Thank You For Choosing SE-Hub!

+

Dear """+name+""":

+ + Your Request for creating a new Campus named """+campus_name + """ + is Being Evaluated. + You Will Receive an e-mail When We finish the process
+ + to access you virtual class. +
+

+ Please let us know if you have any questions. +
+ SE-Hub (c) 2015 niptop Team. + + + """ + message.send() + + +def notify_se_hub_campus_request(campus, campus_name): + message = mail.EmailMessage(sender="SE-Hub Support ", + subject="SE-Hub: "+campus_name+" Is Being Evaluated") + + message.to = 'se-hub@appspot.gserviceaccount.com' + + message.body = """ + a new Campus request + """+str(campus.to_JSON()) + + message.html = """ + +
+
+ + +
+
+
+

New Campus!

+
+ """ + str(campus.to_JSON()) + """ +
+ SE-Hub (c) 2015 niptop Team. + + + """ + message.send() diff --git a/SE_API/Validation_Utils.py b/SE_API/Validation_Utils.py index e99b2bd..90df681 100644 --- a/SE_API/Validation_Utils.py +++ b/SE_API/Validation_Utils.py @@ -2,7 +2,7 @@ __author__ = 'sagi' from google.appengine.ext import db from models.User import User from models.Campus import Campus -from google.appengine.api import mail + def get_user_by_token(token): @@ -32,50 +32,3 @@ def is_lecturer(token): if user is None: return False return user.isLecturer - - -def send_validation_email(token, email, name): - emailSuffix = str(email).split('@')[1] - message = mail.EmailMessage(sender="SE-Hub Support ", - subject="SE-Hub Activate Account") - - message.to = email - - message.body = """ - Dear """+name+""": - - To Activate your SE-Hub Account please click on the link below:
- http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+""" - to get access to your Campus :) - - Please let us know if you have any questions. - - SE-Hub (c) 2015 niptop Team. - """ - - message.html = """ - -
-
- - -
-
-
-

Hey """+name+"""- Just one More Step...

-

Dear """+name+""":

- - To Activate your SE-Hub Account please click on the link below:
- http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+""" - - to access you virtual class. -
-

- Please let us know if you have any questions. -
- SE-Hub (c) 2015 niptop Team. - - - """ - - message.send() diff --git a/Testing/CampusAPI_Test.py b/Testing/CampusAPI_Test.py new file mode 100644 index 0000000..6f0c6e4 --- /dev/null +++ b/Testing/CampusAPI_Test.py @@ -0,0 +1,26 @@ +__author__ = 'etye' +import unittest +import requests +from Testing.config import __CONFIG__ +class UserTestPlan(unittest.TestCase): + def setUpClass(cls): + debug = __CONFIG__['DEBUG'] + if debug: + url = __CONFIG__['PATHS']['DEBUG'] + else: + url = __CONFIG__['PATHS']['PRODUCTION'] + cls.url_ = url + request = requests.get(url+'api/qa/init') + if 200 <= request.status_code <= 299: + print 'Initialized' + + def test_Campuses_invalid(self): + r = requests.get(self.__class__.url_+'api/Campuses/invalidtoken') + self.assertEquals(r.status_code, 403) + def test_Campuses_valid(self): + r = requests.get(self.__class__.url_+'api/Campuses/'+__CONFIG__['TOKENS']['STUDENT']) + self.assertEquals(r.status_code, 200) + self.assertEquals(r.json()['username'], 'qa_student') + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py new file mode 100644 index 0000000..e907400 --- /dev/null +++ b/Testing/UserAPI_Test.py @@ -0,0 +1,44 @@ +__author__ = 'etye' +import unittest +import requests +from Testing.config import __CONFIG__ + +class UserTestPlan(unittest.TestCase): + @classmethod + def setUpClass(cls): + debug = __CONFIG__['DEBUG'] + if debug: + url = __CONFIG__['PATHS']['DEBUG'] + else: + url = __CONFIG__['PATHS']['PRODUCTION'] + cls.url_ = url + request = requests.get(url+'api/qa/init') + if 200 <= request.status_code <= 299: + print 'Initialized' + + def test_getUserByToken_invalid(self): + r = requests.get(self.__class__.url_+'api/users/getUserByToken/invalidtoken') + self.assertEquals(r.status_code, 403) + + def test_getUserByToken_valid(self): + r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT']) + self.assertEquals(r.status_code, 200) + self.assertEquals(r.json()['username'], 'qa_student') + + def test_getUserByToken_empty(self): + r = requests.get(self.__class__.url_+'api/users/getUserByToken/') + self.assertEquals(r.status_code, 400) + + def test_isStudent_Student(self): + r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT']) + self.assertEquals(r.status_code, 200) + self.assertFalse(r.json()['isLecturer']) + + def test_isLecturer_Lecturer(self): + r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER']) + self.assertEquals(r.status_code, 200) + self.assertTrue(r.json()['isLecturer']) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/Testing/__init__.py b/Testing/__init__.py new file mode 100644 index 0000000..b8ecda6 --- /dev/null +++ b/Testing/__init__.py @@ -0,0 +1 @@ +__author__ = 'etye' diff --git a/Testing/config.py b/Testing/config.py new file mode 100644 index 0000000..9e6f48a --- /dev/null +++ b/Testing/config.py @@ -0,0 +1,14 @@ +__author__ = 'etye' + + +__CONFIG__ = { + 'DEBUG': True, + 'PATHS': { + 'DEBUG': 'http://localhost:8080/', + 'PRODUCTION': 'http://se-hub.appspot.com/' + }, + 'TOKENS':{ + 'STUDENT': '_QA_TOKEN_TEST_STUDENT', + 'LECTURER': '_QA_TOKEN_TEST_LECTURER' + } +} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index ea840eb..c5e3215 100644 --- a/templates/index.html +++ b/templates/index.html @@ -32,11 +32,11 @@ - - - - - + + + + + diff --git a/templates/js/controllers/registerController.js b/templates/js/controllers/registerController.js index c8cadcf..5c5e7b0 100644 --- a/templates/js/controllers/registerController.js +++ b/templates/js/controllers/registerController.js @@ -1,45 +1,39 @@ angular.module('SeHub') -.controller('registerController', ['$scope', '$location', '$cookies', 'apiService', '$rootScope', function ($scope, $location, $cookies, apiService ,$rootScope) { +.controller('registerController', ['$scope', '$cookies', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function ($scope, $cookies, $location, $mdToast, $mdDialog, apiService ,$rootScope) +{ $scope.userHasNoName = false; $scope.campusChecked = false; $scope.isEmpty = true; // if the academic email line is empty - // $scope.fullMail = $scope.academicEmail + $scope.campusObj.email_ending; // Will hold the full academic email of the user $rootScope.seToken = $cookies['com.sehub.www']; var token = $rootScope.seToken; - apiService.getUserByToken(token).success(function(data){ + apiService.getUserByToken(token).success(function(data) // Get user token + { $scope.user = data; - console.log(data); + if(data.message == 'No User Found') console.error("No User Found!"); + console.log(data); - $scope.user = data; - $rootScope.user = data; - if($scope.user.isFirstLogin) - $location.path('/register') - - - if($scope.user.name === ";"){ + if($scope.user.name === ";") + { $scope.user.name = ""; $scope.user.name = $scope.user.username $scope.userHasNoName = true; } - apiService.getAllCampuses($scope.user.seToken).success(function(data) - { - $scope.campuses = data; - }).error(function() - { - // TODO - }); + apiService.getAllCampuses($scope.user.seToken).success(function(data) // Get all the campuses + { + $scope.campuses = data; + }).error(function() + { + // TODO + }); }); - - - $scope.dropdownClicked = function() { if($scope.campus){ @@ -51,40 +45,54 @@ angular.module('SeHub') console.log($scope.campusObj); // TODO REMOVE!! } }; - } - + }; }; - $scope.submitClicked = function() + $scope.submitClicked = function(ev) { - console.log($scope.user.AcMail); - $scope.mail = 'pin'; - console.log($scope.mail); + if($scope.user.AcMail != null) + { + var fullMail = $scope.user.AcMail + $scope.campusObj.email_ending; // Holds the full academic email of the user + apiService.sendValidationMail($scope.user.seToken, 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)); + // TODO - ADD DELETE COOKIES + $cookies.remove("com.sehub.www"); + // $location.path("templates/views/home.html"); // Redirecting to home page // TODO REMOVE REMOVE!! + }).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)); + }); + }; }; - - apiService.getAllCampuses($scope.user.seToken).success(function(data) - { - $scope.campuses = data; - }).error(function() - { - // TODO - }); + // TODO FOR LATER + // TODO FOR LATER - // apiService.sendValidationMail($scope.user.seToken, $scope.fullMail).success(function(data) // TODO: Add 2nd parameter email type Email - // { - // console.log($scope.fullMail); - // console.log("200"); - - // // TODO - // }).error(function() - // { - - // }); + $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 + }; + // TODO FOR LATER + // TODO FOR LATER +}]); -}]); \ No newline at end of file diff --git a/templates/js/services/apiService.js b/templates/js/services/apiService.js index e240375..108b309 100644 --- a/templates/js/services/apiService.js +++ b/templates/js/services/apiService.js @@ -7,7 +7,7 @@ service.factory('apiService', ['$http', function($http) { return { getUserByToken: function(token){ - var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/getUserByToken/" + token; + var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/users/getUserByToken/" + token; req = { method : "GET", url : url @@ -16,7 +16,7 @@ service.factory('apiService', ['$http', function($http) { return $http(req); }, getAllCampuses: function(token){ - var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/Campuses/" + token; + var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/campuses/getAll/" + token; req = { method : "GET", url : url diff --git a/templates/views/index.html b/templates/views/index.html index 816e633..0a66c32 100644 --- a/templates/views/index.html +++ b/templates/views/index.html @@ -32,11 +32,11 @@
- - - - - + + + + + diff --git a/templates/views/register.html b/templates/views/register.html index bbe6b26..d73d0d9 100644 --- a/templates/views/register.html +++ b/templates/views/register.html @@ -18,8 +18,8 @@
Are You A Lecturer? - - + +
@@ -37,7 +37,7 @@
- Submit + Submit