Merge branch 'master' of https://github.com/sagidayan/SE-Hub into API_Dev

This commit is contained in:
Aran Zaiger 2015-06-15 16:54:26 +03:00
commit 11ea93f3e7
13 changed files with 285 additions and 111 deletions

View file

@ -20,9 +20,10 @@ from models.Course import Course
from models.Project import Project from models.Project import Project
from models.Campus import Campus from models.Campus import Campus
#Validation Utils Libs # All API
from SE_API.Validation_Utils import * from SE_API.Validation_Utils import *
from SE_API.Respones_Utils import * from SE_API.Respones_Utils import *
from SE_API.Email_Utils import *
from SE_API.UserRoutes import user_routes from SE_API.UserRoutes import user_routes
from SE_API.CampusRoutes import campus_routes from SE_API.CampusRoutes import campus_routes

View file

@ -143,4 +143,4 @@ def get_campuses(token):
@campus_routes.route('/api/campuses/help') @campus_routes.route('/api/campuses/help')
def documentation(): def documentation():
return auto.html() return auto.html()

127
SE_API/Email_Utils.py Normal file
View 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()

View file

@ -2,7 +2,7 @@ __author__ = 'sagi'
from google.appengine.ext import db from google.appengine.ext import db
from models.User import User from models.User import User
from models.Campus import Campus from models.Campus import Campus
from google.appengine.api import mail
def get_user_by_token(token): def get_user_by_token(token):
@ -32,50 +32,3 @@ def is_lecturer(token):
if user is None: if user is None:
return False return False
return user.isLecturer 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
View 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
View 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
View file

@ -0,0 +1 @@
__author__ = 'etye'

14
Testing/config.py Normal file
View 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'
}
}

View file

@ -32,11 +32,11 @@
<!-- Angular Material Dependencies --> <!-- 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.4.0/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.4.0/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.4.0/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.4.0/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-cookies.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular-material.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular-material.min.js"></script>

View file

@ -1,45 +1,39 @@
angular.module('SeHub') 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.userHasNoName = false;
$scope.campusChecked = false; $scope.campusChecked = false;
$scope.isEmpty = true; // if the academic email line is empty $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']; $rootScope.seToken = $cookies['com.sehub.www'];
var token = $rootScope.seToken; var token = $rootScope.seToken;
apiService.getUserByToken(token).success(function(data){ apiService.getUserByToken(token).success(function(data) // Get user token
{
$scope.user = data; $scope.user = data;
console.log(data);
if(data.message == 'No User Found') if(data.message == 'No User Found')
console.error("No User Found!"); console.error("No User Found!");
console.log(data);
$scope.user = data; if($scope.user.name === ";")
$rootScope.user = data; {
if($scope.user.isFirstLogin)
$location.path('/register')
if($scope.user.name === ";"){
$scope.user.name = ""; $scope.user.name = "";
$scope.user.name = $scope.user.username $scope.user.name = $scope.user.username
$scope.userHasNoName = true; $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; $scope.campuses = data;
}).error(function() }).error(function()
{ {
// TODO // TODO
}); });
}); });
$scope.dropdownClicked = function() $scope.dropdownClicked = function()
{ {
if($scope.campus){ if($scope.campus){
@ -51,40 +45,54 @@ angular.module('SeHub')
console.log($scope.campusObj); // TODO REMOVE!! console.log($scope.campusObj); // TODO REMOVE!!
} }
}; };
} };
}; };
$scope.submitClicked = function() $scope.submitClicked = function(ev)
{ {
console.log($scope.user.AcMail); if($scope.user.AcMail != null)
$scope.mail = 'pin'; {
console.log($scope.mail); 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) // TODO FOR LATER
{ // TODO FOR LATER
$scope.campuses = data;
}).error(function()
{
// TODO
});
// apiService.sendValidationMail($scope.user.seToken, $scope.fullMail).success(function(data) // TODO: Add 2nd parameter email type Email $scope.getPopWindowPosition = function()
// { {
// console.log($scope.fullMail); return Object.keys($scope.toastPosition).filter(function(pos)
// console.log("200"); {
return $scope.toastPosition[pos];
// // TODO }).join(' ');
// }).error(function() };
// {
$scope.toastPosition =
// }); {
bottom: false,
top: true,
left: false,
right: true
};
// TODO FOR LATER
// TODO FOR LATER
}]);
}]);

View file

@ -7,7 +7,7 @@ service.factory('apiService', ['$http', function($http) {
return { return {
getUserByToken: function(token){ 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 = { req = {
method : "GET", method : "GET",
url : url url : url
@ -16,7 +16,7 @@ service.factory('apiService', ['$http', function($http) {
return $http(req); return $http(req);
}, },
getAllCampuses: function(token){ 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 = { req = {
method : "GET", method : "GET",
url : url url : url

View file

@ -32,11 +32,11 @@
</div> </div>
</div> </div>
<!-- Angular Material Dependencies --> <!-- 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.4.0/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.4.0/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.4.0/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.4.0/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-cookies.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular-material.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular-material.min.js"></script>

View file

@ -18,8 +18,8 @@
</div> </div>
<div layout="row" layout-align="center center"> <div layout="row" layout-align="center center">
Are You A Lecturer? Are You A Lecturer?
<md-switch ng-model="user.isLecturer" aria-label="Switch 1"> <md-switch class="md-primary" md-no-ink aria-label="Switch No Ink" ng-model="data.cb5">
</md-switch> </md-switch>
</div> </div>
</div> </div>
<div> <div>
@ -37,7 +37,7 @@
</div> </div>
<div> <div>
<div class = "disabledSubmitButton"> <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> </div>
</div> </div>