From 5c5d91ca79e5fb674aaba0d10c4ed028ba398306 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Tue, 9 Jun 2015 20:16:29 +0300 Subject: [PATCH 01/10] Fix To JS Error --- templates/js/app.js | 2 +- templates/js/controllers/mainController.js | 5 +++-- templates/js/services/apiService.js | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) 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/services/apiService.js b/templates/js/services/apiService.js index ef6ebd4..dafc060 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', []); From 8149e4c61f0fed0dd997d91bc70d2572fa72a142 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Tue, 9 Jun 2015 20:53:57 +0300 Subject: [PATCH 02/10] Register Campus picker --- templates/js/controllers/registerController.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 From 9b887c0599ecbb71fadcdba3f6745e3611b6240e Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Wed, 10 Jun 2015 12:44:09 +0300 Subject: [PATCH 03/10] DD and z-index --- templates/css/theme.css | 1 - templates/views/register.html | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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/views/register.html b/templates/views/register.html index e96ea04..c0ffdc5 100644 --- a/templates/views/register.html +++ b/templates/views/register.html @@ -20,7 +20,12 @@ " I Am A Lecturer... ": {{ user.isLecturer }} -
+
+
+ + {{c.title}} + +

Note: This setting can be changed in the future.
But Choose Now for easy Registration... From a37ef482ca93385659477b0aa2544d55f8e7e0bc Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Wed, 10 Jun 2015 13:12:59 +0300 Subject: [PATCH 04/10] API: Added Campus Model - And A new API Call --- SE_API/API.py | 50 ++++++++++++++++++++++++++++++++++---- SE_API/Validation_Utils.py | 11 +++++++++ models/Campus.py | 25 +++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 SE_API/Validation_Utils.py create mode 100644 models/Campus.py diff --git a/SE_API/API.py b/SE_API/API.py index aa2b33b..7f3690e 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -14,6 +14,10 @@ from flask.ext.autodoc import Autodoc # DB Models from models.User import User +from models.Campus import Campus + +#Validation Utils Libs +from SE_API.Validation_Utils import * @@ -98,10 +102,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: @@ -110,13 +111,52 @@ 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' + }, + .... + { + ... + } + ] + + code 403: Forbidden - Invalid Token + code 500: internal server error + """ + if is_user_token_valid(token): + arr = [] + query = User.all() + for c in query.run(): + arr.append(c.to_JSON) + if len(arr) != 0: + return Response(response=json.dumps([]), + 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..e074f13 --- /dev/null +++ b/SE_API/Validation_Utils.py @@ -0,0 +1,11 @@ +__author__ = 'sagi' +from google.appengine.ext import db +from models.User import User + +def is_user_token_valid(token): + query = User.all() + query.filter("seToken = ", token) + + for u in query.run(): + return True + return False diff --git a/models/Campus.py b/models/Campus.py new file mode 100644 index 0000000..de62f31 --- /dev/null +++ b/models/Campus.py @@ -0,0 +1,25 @@ +__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.username, + '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: + +""" \ No newline at end of file From 085047c2bf3e821318546fba70b730a67ae33b63 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Wed, 10 Jun 2015 13:15:41 +0300 Subject: [PATCH 05/10] API: Help page in /api/help --- SE_API/API.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SE_API/API.py b/SE_API/API.py index 7f3690e..3006b58 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -41,7 +41,7 @@ def page_not_found(e): def wellcomePage(): return app.send_static_file('index.html') -@app.route('/api/documentation') +@app.route('/api/help') def documentation(): return auto.html() @@ -125,7 +125,9 @@ def get_campuses(token): :param token: user seToken :return: code 200: - [{'title': 'JCE', + [ + { + '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' From 5bdcff7f517469586088aff6a1dee9d36d288a1f Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Wed, 10 Jun 2015 13:36:31 +0300 Subject: [PATCH 06/10] Angularjs: New api service method getAllCampuses --- templates/js/services/apiService.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/templates/js/services/apiService.js b/templates/js/services/apiService.js index dafc060..b794224 100644 --- a/templates/js/services/apiService.js +++ b/templates/js/services/apiService.js @@ -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); } From 9698a5b4e2e08c1e916b94544748d44d528ae956 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Wed, 10 Jun 2015 13:55:55 +0300 Subject: [PATCH 07/10] API: Campus Hot Fix --- SE_API/API.py | 7 ++++--- models/Campus.py | 13 ++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/SE_API/API.py b/SE_API/API.py index 3006b58..d8f1be3 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -143,11 +143,12 @@ def get_campuses(token): """ if is_user_token_valid(token): arr = [] - query = User.all() + query = Campus.all() for c in query.run(): - arr.append(c.to_JSON) + arr.append(dict(json.loads(c.to_JSON()))) + print arr if len(arr) != 0: - return Response(response=json.dumps([]), + return Response(response=json.dumps(arr), status=200, mimetype="application/json") else: diff --git a/models/Campus.py b/models/Campus.py index de62f31..4859409 100644 --- a/models/Campus.py +++ b/models/Campus.py @@ -11,7 +11,7 @@ class Campus(db.Model): master_user_id = db.IntegerProperty(required=True) def to_JSON(self): - dick = {'title': self.username, + dick = {'title': self.title, 'email_ending': self.email_ending, 'master_user_id': self.master_user_id, 'avatar_url': self.avatar_url @@ -21,5 +21,12 @@ class Campus(db.Model): """ DEBUG Script - To create a campus: - -""" \ No newline at end of file +""" +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 From 942764af6a00255b01861cee629b6d14eb0a57b4 Mon Sep 17 00:00:00 2001 From: Matan Bar Yosef Date: Wed, 10 Jun 2015 16:04:24 +0300 Subject: [PATCH 08/10] dropdown added fixed submit button --- templates/views/register.html | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/templates/views/register.html b/templates/views/register.html index c0ffdc5..3312902 100644 --- a/templates/views/register.html +++ b/templates/views/register.html @@ -1,5 +1,4 @@

-

Registration

@@ -21,11 +20,18 @@
-
- + +
+ Submit + +
+

Note: This setting can be changed in the future.
But Choose Now for easy Registration... From 5f4fbfcf61031a8c0431903f3c594a48350f7fd1 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Wed, 10 Jun 2015 17:41:49 +0300 Subject: [PATCH 09/10] Use Model Changes added camuses_id_list & classes_id_lists --- models/User.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/models/User.py b/models/User.py index e2aa922..9a990ee 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): dick = {'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(dick) \ No newline at end of file From 3c5eba4fea4c4d3b83f41c05cb2b2b9e9bf7772a Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Wed, 10 Jun 2015 18:47:53 +0300 Subject: [PATCH 10/10] API: Added A Route To Send Validation Emails. See /api/help --- SE_API/API.py | 39 +++++++++++++++++++++++++++++--- SE_API/Validation_Utils.py | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/SE_API/API.py b/SE_API/API.py index d8f1be3..e7064e9 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -41,6 +41,39 @@ def page_not_found(e): def wellcomePage(): return app.send_static_file('index.html') +@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() @@ -67,8 +100,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, @@ -135,7 +168,7 @@ def get_campuses(token): .... { ... - } + }req ] code 403: Forbidden - Invalid Token diff --git a/SE_API/Validation_Utils.py b/SE_API/Validation_Utils.py index e074f13..836e4d1 100644 --- a/SE_API/Validation_Utils.py +++ b/SE_API/Validation_Utils.py @@ -1,6 +1,8 @@ __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() @@ -9,3 +11,47 @@ def is_user_token_valid(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()