diff --git a/SE_API/API.py b/SE_API/API.py index f298ffc..56c5583 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -16,6 +16,10 @@ from flask.ext.autodoc import Autodoc from models.User import User from models.Course import Course from models.Project import Project +from models.Campus import Campus + +#Validation Utils Libs +from SE_API.Validation_Utils import * @@ -39,7 +43,40 @@ def page_not_found(e): def wellcomePage(): return app.send_static_file('index.html') -@app.route('/api/documentation') +@app.route('/api/validatation/sendmail/', methods=['POST']) +@auto.doc() +def send_activation(token): + """ + This Method Will Send An Email To The User - To Confirm his Account + :param token: - seToken + :payload: JSON - {email: 'academic@email.ac.com'} + :return: + 200 - Email Sent - No Response + 400 - Bad Request + 403 - Invalid Token + """ + if not request.data: + return Response(response=json.dumps({'message': 'Bad Request'}), + status=400, + mimetype="application/json") + payload = json.loads(request.data) + if not is_user_token_valid(token): + return Response(response=json.dumps({'message': 'Not A Valid Token!'}), + status=403, + mimetype="application/json") + query = User.all() + query.filter('seToken =', token) + for u in query.run(limit=1): + try: + send_validation_email(token=token, name=u.username, email=payload["email"]) + except Exception: + return Response(response=json.dumps({'message': 'Bad Request'}), + status=400, + mimetype="application/json") + + return Response(status=200) + +@app.route('/api/help') def documentation(): return auto.html() @@ -65,8 +102,8 @@ def getUserByToken(token): for u in query.run(limit=5): return Response(response=u.to_JSON(), - status=201, - mimetype="application/json") # Real response! + status=201, + mimetype="application/json") # Real response! return Response(response=json.dumps({'message' : 'No User Found'}), status=400, @@ -74,8 +111,6 @@ def getUserByToken(token): - - @app.route('/githubOAuth') @cross_origin('*') @github.authorized_handler @@ -102,10 +137,7 @@ def oauth(oauth_token): u.put() return cookieMonster(u.seToken) - if user_data["name"] == "": - tempName = ";" - else: - tempName = user_data["name"] + tempName = ";" if user_data["email"] == "": for email in userEmails: @@ -114,13 +146,55 @@ def oauth(oauth_token): else: tempEmail = user_data["email"] - user = User(username=user_data["login"], name=tempName, avatar_url=user_data["avatar_url"], email=tempEmail, isLecturer=False, accsessToken=oauth_token, seToken=str(uuid.uuid4())) db.put(user) db.save return cookieMonster(user.seToken) +@app.route('/api/Campuses/', methods=['GET']) +@auto.doc() +def get_campuses(token): + """ + This Call will return an array of all Campuses available + :param token: user seToken + :return: + code 200: + [ + { + 'title': 'JCE', + 'email_ending': '@post.jce.ac.il', + 'master_user_id': 123453433341, (User that created the campus) + 'avatar_url': 'http://some.domain.com/imagefile.jpg' + }, + .... + { + ... + }req + ] + + code 403: Forbidden - Invalid Token + code 500: internal server error + """ + if is_user_token_valid(token): + arr = [] + query = Campus.all() + for c in query.run(): + arr.append(dict(json.loads(c.to_JSON()))) + print arr + if len(arr) != 0: + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") + else: + return Response(response=[], + status=200, + mimetype="application/json") + else: + return Response(response=json.dumps({'message': 'Invalid Token'}), + status=403, + mimetype="application/json") + @app.route('/login') diff --git a/SE_API/Validation_Utils.py b/SE_API/Validation_Utils.py new file mode 100644 index 0000000..836e4d1 --- /dev/null +++ b/SE_API/Validation_Utils.py @@ -0,0 +1,57 @@ +__author__ = 'sagi' +from google.appengine.ext import db +from models.User import User +from google.appengine.api import mail + + +def is_user_token_valid(token): + query = User.all() + query.filter("seToken = ", token) + + for u in query.run(): + return True + return False + +def send_validation_email(token, email, name): + 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/validatation/confirm/"""+token+""" + to access you virtual class. + + 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/validatation/confirm/"""+token+"""

+ + 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/models/Campus.py b/models/Campus.py new file mode 100644 index 0000000..4859409 --- /dev/null +++ b/models/Campus.py @@ -0,0 +1,32 @@ +__author__ = 'sagi' + +import json + +from google.appengine.ext import db + +class Campus(db.Model): + title = db.StringProperty(required=True) + avatar_url = db.StringProperty(required=True) + email_ending = db.StringProperty(required=True) + master_user_id = db.IntegerProperty(required=True) + + def to_JSON(self): + dick = {'title': self.title, + 'email_ending': self.email_ending, + 'master_user_id': self.master_user_id, + 'avatar_url': self.avatar_url + } + return json.dumps(dick) + + +""" +DEBUG Script - To create a campus: +""" +is_jce_in = False +query = Campus.all() +query.filter('title =', 'JCE') +for c in query.run(): + is_jce_in = True +if not is_jce_in: + jce = Campus(title='JCE', email_ending='@post.jce.ac.il', master_user_id=111, avatar_url='https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg') + db.put(jce) \ No newline at end of file diff --git a/models/User.py b/models/User.py index 8ce26a0..ed0e2c1 100644 --- a/models/User.py +++ b/models/User.py @@ -12,6 +12,8 @@ class User(db.Model): seToken = db.StringProperty(required=True) avatar_url = db.StringProperty(required=True) isFirstLogin = db.BooleanProperty(default=True) + campuses_id_list = db.StringListProperty() + classes_id_list = db.StringListProperty() def to_JSON(self): data = {'username' : self.username, @@ -21,5 +23,7 @@ class User(db.Model): 'seToken' : self.seToken, 'avatar_url' : self.avatar_url, 'isFirstLogin' : self.isFirstLogin, + 'campuses_id_list': self.campuses_id_list, + 'classes_id_list': self.classes_id_list } - return json.dumps(data) \ No newline at end of file + return json.dumps(data) diff --git a/templates/css/theme.css b/templates/css/theme.css index d9866bb..641b870 100644 --- a/templates/css/theme.css +++ b/templates/css/theme.css @@ -39,7 +39,6 @@ body.noscroll position: fixed; width:40%; height:400px; - z-index:200; margin: auto; margin-top: 15%; left: 0; diff --git a/templates/js/app.js b/templates/js/app.js index e0d58d8..46b8d12 100644 --- a/templates/js/app.js +++ b/templates/js/app.js @@ -1,4 +1,4 @@ -var DEBUG = false; +var DEBUG = true; var welcome = angular.module('welcome', ['ngMaterial', 'seHub.services', 'ngRoute' , 'ngCookies']); diff --git a/templates/js/controllers/mainController.js b/templates/js/controllers/mainController.js index 6e184b4..c27cf90 100644 --- a/templates/js/controllers/mainController.js +++ b/templates/js/controllers/mainController.js @@ -6,11 +6,12 @@ angular.module('SeHub') $scope.loadingData = true; apiService.getUserByToken(token).success(function(data){ + console.log(data); if(data.message == 'No User Found') console.error("No User Found!"); - $scope.user = data._entity; - $rootScope.user = data._entity; + $scope.user = data; + $rootScope.user = data; if($scope.user.isFirstLogin) $location.path('/register') }) diff --git a/templates/js/controllers/registerController.js b/templates/js/controllers/registerController.js index b6cc986..f403fb4 100644 --- a/templates/js/controllers/registerController.js +++ b/templates/js/controllers/registerController.js @@ -10,5 +10,21 @@ angular.module('SeHub') $scope.userHasNoName = true; } + ///TESTING + $scope.campuses = [ + { + title: 'JCE', + capus_avatar: "http://asdasfa.asdasd.com/img.jpg" + }, + { + title: 'JCE1', + capus_avatar: "http://asdasfa.asdasd.com/img.jpg" + }, + { + title: "JCE2", + capus_avatar: "http://asdasfa.asdasd.com/img.jpg" + } + ]; -}]) \ No newline at end of file + +}]); \ No newline at end of file diff --git a/templates/js/services/apiService.js b/templates/js/services/apiService.js index ef6ebd4..b794224 100644 --- a/templates/js/services/apiService.js +++ b/templates/js/services/apiService.js @@ -1,4 +1,4 @@ -var DEBUG = false; +var DEBUG = true; var service = angular.module('seHub.services', []); @@ -12,6 +12,15 @@ service.factory('apiService', ['$http', function($http) { method : "GET", url : url + }; + return $http(req); + }, + getAllCampuses: function(token){ + var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/Campuses/" + token; + req = { + method : "GET", + url : url + }; return $http(req); } diff --git a/templates/views/register.html b/templates/views/register.html index e96ea04..3312902 100644 --- a/templates/views/register.html +++ b/templates/views/register.html @@ -1,5 +1,4 @@
-

Registration

@@ -20,7 +19,19 @@ " I Am A Lecturer... ": {{ user.isLecturer }}
-
+
+ +
+ Submit + +
+

Note: This setting can be changed in the future.
But Choose Now for easy Registration...