From ce8efbcaa99ff685bc90cd0057bdba55282f9108 Mon Sep 17 00:00:00 2001 From: Matan Bar Yosef Date: Sun, 14 Jun 2015 20:06:00 +0300 Subject: [PATCH 01/11] Email verification added- empty user name test added --- .../js/controllers/registerController.js | 51 ++++++------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/templates/js/controllers/registerController.js b/templates/js/controllers/registerController.js index c8cadcf..5be6f7f 100644 --- a/templates/js/controllers/registerController.js +++ b/templates/js/controllers/registerController.js @@ -1,25 +1,19 @@ angular.module('SeHub') -.controller('registerController', ['$scope', '$location', '$cookies', 'apiService', '$rootScope', function ($scope, $location, $cookies, apiService ,$rootScope) { +.controller('registerController', ['$scope', '$cookies', 'apiService', '$rootScope', function ($scope, $cookies, 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){ $scope.user = data; - console.log(data); + if(data.message == 'No User Found') console.error("No User Found!"); - - $scope.user = data; - $rootScope.user = data; - if($scope.user.isFirstLogin) - $location.path('/register') - + console.log(data); if($scope.user.name === ";"){ $scope.user.name = ""; @@ -38,8 +32,6 @@ angular.module('SeHub') }); - - $scope.dropdownClicked = function() { if($scope.campus){ @@ -51,37 +43,26 @@ angular.module('SeHub') console.log($scope.campusObj); // TODO REMOVE!! } }; - } - + }; }; $scope.submitClicked = function() { - 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) // TODO: Add 2nd parameter email type Email + { + console.log("DONE - 200"); + // TODO - add a window that display that an email has been sent for verification + }).error(function() + { + // TODO + }); + }; }; - - apiService.getAllCampuses($scope.user.seToken).success(function(data) - { - $scope.campuses = data; - }).error(function() - { - // TODO - }); - - // 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() - // { - - // }); From cadb95651ed603bc31644a291fda87f81d8e1dfd Mon Sep 17 00:00:00 2001 From: Matan Bar Yosef Date: Sun, 14 Jun 2015 20:22:00 +0300 Subject: [PATCH 02/11] Email verification added- empty user name test added --- templates/js/controllers/registerController.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/js/controllers/registerController.js b/templates/js/controllers/registerController.js index 5be6f7f..5c93628 100644 --- a/templates/js/controllers/registerController.js +++ b/templates/js/controllers/registerController.js @@ -8,7 +8,8 @@ angular.module('SeHub') $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; if(data.message == 'No User Found') @@ -21,7 +22,7 @@ angular.module('SeHub') $scope.userHasNoName = true; } - apiService.getAllCampuses($scope.user.seToken).success(function(data) + apiService.getAllCampuses($scope.user.seToken).success(function(data) // Get all the campuses { $scope.campuses = data; }).error(function() From 0a2f209311ea0bd0600f942c48a402f7c2e8f68b Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sun, 14 Jun 2015 22:05:16 +0300 Subject: [PATCH 03/11] Update AngularJS --- templates/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 @@ - - - - - + + + + + From c3e39e895a37e5fc03cef499a1c5fe91ce5e0aba Mon Sep 17 00:00:00 2001 From: Matan Bar Yosef Date: Sun, 14 Jun 2015 22:06:27 +0300 Subject: [PATCH 04/11] registration submit skeleton --- .../js/controllers/registerController.js | 58 ++++++++++++++----- templates/views/register.html | 6 +- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/templates/js/controllers/registerController.js b/templates/js/controllers/registerController.js index 5c93628..5c5e7b0 100644 --- a/templates/js/controllers/registerController.js +++ b/templates/js/controllers/registerController.js @@ -1,5 +1,6 @@ angular.module('SeHub') -.controller('registerController', ['$scope', '$cookies', 'apiService', '$rootScope', function ($scope, $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; @@ -16,23 +17,23 @@ angular.module('SeHub') console.error("No User Found!"); console.log(data); - 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) // Get all the campuses - { - $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){ @@ -47,26 +48,51 @@ angular.module('SeHub') }; }; - $scope.submitClicked = function() + $scope.submitClicked = function(ev) { 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) // TODO: Add 2nd parameter email type Email + apiService.sendValidationMail($scope.user.seToken, fullMail).success(function(data) { - console.log("DONE - 200"); - // TODO - add a window that display that an email has been sent for verification + 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() { - // TODO + $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)); }); }; }; + // 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 + }; + + // TODO FOR LATER + // TODO FOR LATER +}]); -}]); \ No newline at end of file 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
From ef28a39720e5c1126a292a08eb236e4e7f03acab Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sun, 14 Jun 2015 22:09:08 +0300 Subject: [PATCH 05/11] Update AngularJS in App --- templates/views/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 @@ - - - - - + + + + + From 9ea00145f90267180a60a29a98db574fe48ac66d Mon Sep 17 00:00:00 2001 From: etyemyer Date: Sun, 14 Jun 2015 22:49:10 +0300 Subject: [PATCH 06/11] UserApi_Test - test getuserbytoken with valid,invalid and empty string CampusesApi_test - with valid,invalid string --- Testing/CampusAPI_Test.py | 26 ++++++++++++++++++++++++++ Testing/UserAPI_Test.py | 37 +++++++++++++++++++++++++++++++++++++ Testing/__init__.py | 1 + Testing/config.py | 14 ++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 Testing/CampusAPI_Test.py create mode 100644 Testing/UserAPI_Test.py create mode 100644 Testing/__init__.py create mode 100644 Testing/config.py 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..67b9cf6 --- /dev/null +++ b/Testing/UserAPI_Test.py @@ -0,0 +1,37 @@ +__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/getUserByToken/invalidtoken') + self.assertEquals(r.status_code, 403) + + + def test_getUserByToken_valid(self): + r = requests.get(self.__class__.url_+'api/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/getUserByToken/') + self.assertEquals(r.status_code, 400) + + + +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 From 831617ac15c30348c2b9a2e09a1f7eb1c9f8bae3 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sun, 14 Jun 2015 23:01:47 +0300 Subject: [PATCH 07/11] Made Email_Utils --- SE_API/API.py | 3 +- SE_API/Email_Utils.py | 127 +++++++++++++++++++++++++++++++++++++ SE_API/Validation_Utils.py | 49 +------------- 3 files changed, 130 insertions(+), 49 deletions(-) create mode 100644 SE_API/Email_Utils.py diff --git a/SE_API/API.py b/SE_API/API.py index 91cfb16..3f6be11 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -19,9 +19,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 * 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() From d0c91b0c704852d6f82ccea1e7faff98eb552a87 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Mon, 15 Jun 2015 16:23:42 +0300 Subject: [PATCH 08/11] AngularJS: Updating Services to the new API scheme --- templates/js/services/apiService.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/js/services/apiService.js b/templates/js/services/apiService.js index e240375..ea599f4 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/" + token; req = { method : "GET", url : url From 97af27500d9e3cbc9ba534e6e3b28a23a30d0f3d Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Mon, 15 Jun 2015 16:24:01 +0300 Subject: [PATCH 09/11] QA: Pormatting UserAPI_Test --- Testing/UserAPI_Test.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py index 67b9cf6..598ea85 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -20,13 +20,11 @@ class UserTestPlan(unittest.TestCase): r = requests.get(self.__class__.url_+'api/getUserByToken/invalidtoken') self.assertEquals(r.status_code, 403) - def test_getUserByToken_valid(self): r = requests.get(self.__class__.url_+'api/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/getUserByToken/') self.assertEquals(r.status_code, 400) From 2dc319af48106e2a8b22fd06944a3c0e9c064ad8 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Mon, 15 Jun 2015 16:28:54 +0300 Subject: [PATCH 10/11] QA: Update UserAPI_Test.py to new API scheme --- Testing/UserAPI_Test.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py index 598ea85..e907400 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -17,18 +17,27 @@ class UserTestPlan(unittest.TestCase): print 'Initialized' def test_getUserByToken_invalid(self): - r = requests.get(self.__class__.url_+'api/getUserByToken/invalidtoken') + 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/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT']) + 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/getUserByToken/') + 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__': From 1ec45d107cb38b1df49deff755b21f6fc1a9ec44 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Mon, 15 Jun 2015 16:51:13 +0300 Subject: [PATCH 11/11] API & AngularJS: Updating API Routes - API_Dev Merge and Service Update --- SE_API/CampusRoutes.py | 2 +- templates/js/services/apiService.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index 93afc55..a93c187 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -188,4 +188,4 @@ def getCampusId(name): @campus_routes.route('/api/campuses/help') def documentation(): - return auto.html() \ No newline at end of file + return auto.html() diff --git a/templates/js/services/apiService.js b/templates/js/services/apiService.js index ea599f4..108b309 100644 --- a/templates/js/services/apiService.js +++ b/templates/js/services/apiService.js @@ -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