Merge branch 'master' of https://github.com/sagidayan/SE-Hub into API_Dev
This commit is contained in:
commit
11ea93f3e7
13 changed files with 285 additions and 111 deletions
|
@ -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
|
||||
|
|
127
SE_API/Email_Utils.py
Normal file
127
SE_API/Email_Utils.py
Normal file
|
@ -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 <se-hub@appspot.gserviceaccount.com>",
|
||||
subject="SE-Hub Activate Account")
|
||||
|
||||
message.to = email
|
||||
|
||||
message.body = """
|
||||
Dear """+name+""":
|
||||
|
||||
To Activate your SE-Hub Account please click on the link below:<br>
|
||||
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 = """
|
||||
<html><head></head><body>
|
||||
<div>
|
||||
<center>
|
||||
<img src='https://cloud.githubusercontent.com/assets/2984053/6825467/7c9d0402-d303-11e4-9827-62a6d66f937a.png'>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
|
||||
</center>
|
||||
</div>
|
||||
<div style='width:70%'>
|
||||
<h1>Hey """+name+"""- Just one More Step...</h1>
|
||||
<h3>Dear """+name+""":</h3>
|
||||
|
||||
To Activate your SE-Hub Account please click on the link below:<br>
|
||||
http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+"""
|
||||
|
||||
to access you virtual class.
|
||||
</div>
|
||||
<br><br>
|
||||
Please let us know if you have any questions.
|
||||
<br>
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
message.send()
|
||||
|
||||
def send_create_campus_request(email, name, campus_name):
|
||||
message = mail.EmailMessage(sender="SE-Hub Support <se-hub@appspot.gserviceaccount.com>",
|
||||
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<br>
|
||||
|
||||
Please let us know if you have any questions.
|
||||
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
"""
|
||||
|
||||
message.html = """
|
||||
<html><head></head><body>
|
||||
<div>
|
||||
<center>
|
||||
<img src='https://cloud.githubusercontent.com/assets/2984053/6825467/7c9d0402-d303-11e4-9827-62a6d66f937a.png'>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
|
||||
</center>
|
||||
</div>
|
||||
<div style='width:70%'>
|
||||
<h1>Thank You For Choosing SE-Hub!</h1>
|
||||
<h3>Dear """+name+""":</h3>
|
||||
|
||||
Your Request for creating a new Campus named """+campus_name + """
|
||||
is Being Evaluated.
|
||||
You Will Receive an e-mail When We finish the process<br>
|
||||
|
||||
to access you virtual class.
|
||||
</div>
|
||||
<br><br>
|
||||
Please let us know if you have any questions.
|
||||
<br>
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
message.send()
|
||||
|
||||
|
||||
def notify_se_hub_campus_request(campus, campus_name):
|
||||
message = mail.EmailMessage(sender="SE-Hub Support <se-hub@appspot.gserviceaccount.com>",
|
||||
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 = """
|
||||
<html><head></head><body>
|
||||
<div>
|
||||
<center>
|
||||
<img src='https://cloud.githubusercontent.com/assets/2984053/6825467/7c9d0402-d303-11e4-9827-62a6d66f937a.png'>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
|
||||
</center>
|
||||
</div>
|
||||
<div style='width:70%'>
|
||||
<h1>New Campus!</h1>
|
||||
<br>
|
||||
""" + str(campus.to_JSON()) + """
|
||||
<br>
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
message.send()
|
|
@ -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 <se-hub@appspot.gserviceaccount.com>",
|
||||
subject="SE-Hub Activate Account")
|
||||
|
||||
message.to = email
|
||||
|
||||
message.body = """
|
||||
Dear """+name+""":
|
||||
|
||||
To Activate your SE-Hub Account please click on the link below:<br>
|
||||
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 = """
|
||||
<html><head></head><body>
|
||||
<div>
|
||||
<center>
|
||||
<img src='https://cloud.githubusercontent.com/assets/2984053/6825467/7c9d0402-d303-11e4-9827-62a6d66f937a.png'>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
|
||||
</center>
|
||||
</div>
|
||||
<div style='width:70%'>
|
||||
<h1>Hey """+name+"""- Just one More Step...</h1>
|
||||
<h3>Dear """+name+""":</h3>
|
||||
|
||||
To Activate your SE-Hub Account please click on the link below:<br>
|
||||
http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+"""
|
||||
|
||||
to access you virtual class.
|
||||
</div>
|
||||
<br><br>
|
||||
Please let us know if you have any questions.
|
||||
<br>
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
message.send()
|
||||
|
|
26
Testing/CampusAPI_Test.py
Normal file
26
Testing/CampusAPI_Test.py
Normal file
|
@ -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()
|
44
Testing/UserAPI_Test.py
Normal file
44
Testing/UserAPI_Test.py
Normal file
|
@ -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()
|
1
Testing/__init__.py
Normal file
1
Testing/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
__author__ = 'etye'
|
14
Testing/config.py
Normal file
14
Testing/config.py
Normal file
|
@ -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'
|
||||
}
|
||||
}
|
|
@ -32,11 +32,11 @@
|
|||
|
||||
|
||||
<!-- Angular Material Dependencies -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-route.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-animate.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular-aria.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-cookies.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-route.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-animate.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-aria.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-cookies.js"></script>
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular-material.min.js"></script>
|
||||
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// TODO FOR LATER
|
||||
// TODO FOR LATER
|
||||
|
||||
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()
|
||||
// {
|
||||
|
||||
// });
|
||||
|
||||
$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
|
||||
|
||||
|
||||
}]);
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -32,11 +32,11 @@
|
|||
</div>
|
||||
</div>
|
||||
<!-- Angular Material Dependencies -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-route.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-animate.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-aria.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-cookies.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-route.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-animate.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-aria.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-cookies.js"></script>
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular-material.min.js"></script>
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
</div>
|
||||
<div layout="row" layout-align="center center">
|
||||
Are You A Lecturer?
|
||||
<md-switch ng-model="user.isLecturer" aria-label="Switch 1">
|
||||
</md-switch>
|
||||
<md-switch class="md-primary" md-no-ink aria-label="Switch No Ink" ng-model="data.cb5">
|
||||
</md-switch>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
|
@ -37,7 +37,7 @@
|
|||
</div>
|
||||
<div>
|
||||
<div class = "disabledSubmitButton">
|
||||
<md-button ng-click="submitClicked()" ng-disabled="!campusChecked" class="md-raised md-primary">Submit</md-button>
|
||||
<md-button ng-click="submitClicked($event)" ng-disabled="!campusChecked" class="md-raised md-primary">Submit</md-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue