Merge branch 'master' of github.com:sagidayan/SE-Hub
This commit is contained in:
commit
eace60fcac
5 changed files with 83 additions and 7 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
__author__ = 'sagi'
|
__author__ = 'sagi'
|
||||||
import json
|
import json
|
||||||
from GithubAPI.GithubAPI import GitHubAPI_Keys
|
from GithubAPI.GithubAPI import GitHubAPI_Keys
|
||||||
|
@ -20,6 +21,7 @@ from models.Campus import Campus
|
||||||
|
|
||||||
#Validation Utils Libs
|
#Validation Utils Libs
|
||||||
from SE_API.Validation_Utils import *
|
from SE_API.Validation_Utils import *
|
||||||
|
from SE_API.Respones_Utils import *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +154,7 @@ def oauth(oauth_token):
|
||||||
|
|
||||||
print user_data["login"]
|
print user_data["login"]
|
||||||
|
|
||||||
for u in resault.run(limit=5):
|
for u in resault.run():
|
||||||
print "Exists!!!"
|
print "Exists!!!"
|
||||||
u.seToken = str(uuid.uuid4())
|
u.seToken = str(uuid.uuid4())
|
||||||
u.accessToken = oauth_token
|
u.accessToken = oauth_token
|
||||||
|
@ -174,6 +176,52 @@ def oauth(oauth_token):
|
||||||
return cookieMonster(user.seToken)
|
return cookieMonster(user.seToken)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/Campuses/create/<string:token>', methods=['POST'])
|
||||||
|
@auto.doc()
|
||||||
|
def create_campus(token):
|
||||||
|
"""
|
||||||
|
This call will create a new campus in the DB
|
||||||
|
:param token: user seToken
|
||||||
|
Payload
|
||||||
|
{'title': self.title,
|
||||||
|
'email_ending': self.email_ending,
|
||||||
|
'avatar_url': self.avatar_url
|
||||||
|
}
|
||||||
|
:return:
|
||||||
|
code 200
|
||||||
|
"""
|
||||||
|
print "1\n"
|
||||||
|
if not request.data:
|
||||||
|
return Response(response=json.dumps({'message': 'Bad Request0'}),
|
||||||
|
status=400,
|
||||||
|
mimetype="application/json")
|
||||||
|
payload = json.loads(request.data)
|
||||||
|
if not is_lecturer(token): #todo: change to lecturer id
|
||||||
|
return Response(response=json.dumps({'message': 'Invalid token or not a lecturer!'}),
|
||||||
|
status=403,
|
||||||
|
mimetype="application/json")
|
||||||
|
|
||||||
|
user = get_user_by_token(token)
|
||||||
|
|
||||||
|
#todo: check legality
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
campus = Campus(title=payload['title'], email_ending=payload['email_ending'], master_user_id=user.key().id(), avatar_url=payload['avatar_url'])
|
||||||
|
except Exception:
|
||||||
|
return Response(response=json.dumps({'message': 'Bad Request1'}),
|
||||||
|
status=400,
|
||||||
|
mimetype="application/json")
|
||||||
|
|
||||||
|
db.put(campus)
|
||||||
|
db.save
|
||||||
|
return Response(response=json.dumps(campus.to_JSON()),
|
||||||
|
status=200,
|
||||||
|
mimetype="application/json")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/Campuses/<string:token>', methods=['GET'])
|
@app.route('/api/Campuses/<string:token>', methods=['GET'])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def get_campuses(token):
|
def get_campuses(token):
|
||||||
|
|
15
SE_API/Respones_Utils.py
Normal file
15
SE_API/Respones_Utils.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
__author__ = 'Aran'
|
||||||
|
|
||||||
|
from flask import Response
|
||||||
|
import json
|
||||||
|
|
||||||
|
def bad_request():
|
||||||
|
return Response(response=json.dumps({'message': 'Bad Request'}),
|
||||||
|
status=400,
|
||||||
|
mimetype="application/json")
|
||||||
|
|
||||||
|
|
||||||
|
def forbidden(message={'message': 'Forbidden'}):
|
||||||
|
return Response(response=json.dumps(message),
|
||||||
|
status=403,
|
||||||
|
mimetype="application/json")
|
|
@ -4,14 +4,27 @@ from models.User import User
|
||||||
from google.appengine.api import mail
|
from google.appengine.api import mail
|
||||||
|
|
||||||
|
|
||||||
def is_user_token_valid(token):
|
def get_user_by_token(token):
|
||||||
query = User.all()
|
query = User.all()
|
||||||
query.filter("seToken = ", token)
|
query.filter("seToken = ", token)
|
||||||
|
|
||||||
for u in query.run():
|
for u in query.run(limit = 1):
|
||||||
|
return u
|
||||||
|
return None
|
||||||
|
|
||||||
|
def is_user_token_valid(token):
|
||||||
|
user = get_user_by_token(token)
|
||||||
|
if user is not None:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def is_lecturer(token):
|
||||||
|
user = get_user_by_token(token)
|
||||||
|
if user is None:
|
||||||
|
return False
|
||||||
|
return user.isLecturer
|
||||||
|
|
||||||
|
|
||||||
def send_validation_email(token, email, name):
|
def send_validation_email(token, email, name):
|
||||||
emailSuffix = str(email).split('@')[1]
|
emailSuffix = str(email).split('@')[1]
|
||||||
message = mail.EmailMessage(sender="SE-Hub Support <se-hub@appspot.gserviceaccount.com>",
|
message = mail.EmailMessage(sender="SE-Hub Support <se-hub@appspot.gserviceaccount.com>",
|
||||||
|
|
|
@ -11,12 +11,12 @@ class Campus(db.Model):
|
||||||
master_user_id = db.IntegerProperty(required=True)
|
master_user_id = db.IntegerProperty(required=True)
|
||||||
|
|
||||||
def to_JSON(self):
|
def to_JSON(self):
|
||||||
dick = {'title': self.title,
|
data = {'title': self.title,
|
||||||
'email_ending': self.email_ending,
|
'email_ending': self.email_ending,
|
||||||
'master_user_id': self.master_user_id,
|
'master_user_id': self.master_user_id,
|
||||||
'avatar_url': self.avatar_url
|
'avatar_url': self.avatar_url
|
||||||
}
|
}
|
||||||
return json.dumps(dick)
|
return json.dumps(data)
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -12,8 +12,8 @@ class User(db.Model):
|
||||||
seToken = db.StringProperty(required=True)
|
seToken = db.StringProperty(required=True)
|
||||||
avatar_url = db.StringProperty(required=True)
|
avatar_url = db.StringProperty(required=True)
|
||||||
isFirstLogin = db.BooleanProperty(default=True)
|
isFirstLogin = db.BooleanProperty(default=True)
|
||||||
campuses_id_list = db.StringListProperty()
|
campuses_id_list = db.StringListProperty(default=[])
|
||||||
classes_id_list = db.StringListProperty()
|
classes_id_list = db.StringListProperty(default=[])
|
||||||
|
|
||||||
def to_JSON(self):
|
def to_JSON(self):
|
||||||
data = {'username' : self.username,
|
data = {'username' : self.username,
|
||||||
|
|
Loading…
Reference in a new issue