2015-06-10 10:12:59 +00:00
|
|
|
__author__ = 'sagi'
|
|
|
|
from google.appengine.ext import db
|
|
|
|
from models.User import User
|
2015-06-11 19:46:18 +00:00
|
|
|
from models.Campus import Campus
|
2015-06-14 20:01:47 +00:00
|
|
|
|
2015-06-10 15:47:53 +00:00
|
|
|
|
2015-06-10 10:12:59 +00:00
|
|
|
|
2015-06-11 18:01:58 +00:00
|
|
|
def get_user_by_token(token):
|
2015-06-10 10:12:59 +00:00
|
|
|
query = User.all()
|
|
|
|
query.filter("seToken = ", token)
|
|
|
|
|
2015-06-11 18:01:58 +00:00
|
|
|
for u in query.run(limit = 1):
|
|
|
|
return u
|
|
|
|
return None
|
|
|
|
|
2015-06-26 11:55:08 +00:00
|
|
|
def get_user_by_id(id):
|
|
|
|
u = User.get_by_id(id)
|
|
|
|
return u
|
|
|
|
|
2015-06-21 19:19:49 +00:00
|
|
|
def get_campus_by_campusName(campusName):
|
|
|
|
query = Campus.all()
|
|
|
|
query.filter("title = ", campusName)
|
|
|
|
|
|
|
|
for u in query.run(limit = 1):
|
|
|
|
return u
|
|
|
|
return None
|
|
|
|
|
2015-06-11 19:46:18 +00:00
|
|
|
def get_campus_by_suffix(suffix):
|
|
|
|
query = Campus.all()
|
|
|
|
query.filter("email_ending = ", suffix)
|
|
|
|
|
|
|
|
for c in query.run(limit = 1):
|
|
|
|
return c
|
|
|
|
return None
|
|
|
|
|
2015-06-11 18:01:58 +00:00
|
|
|
def is_user_token_valid(token):
|
|
|
|
user = get_user_by_token(token)
|
|
|
|
if user is not None:
|
2015-06-10 10:12:59 +00:00
|
|
|
return True
|
|
|
|
return False
|
2015-06-10 15:47:53 +00:00
|
|
|
|
2015-06-11 18:01:58 +00:00
|
|
|
def is_lecturer(token):
|
|
|
|
user = get_user_by_token(token)
|
|
|
|
if user is None:
|
|
|
|
return False
|
|
|
|
return user.isLecturer
|