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