UserApi_Test
CampusesApi_test
This commit is contained in:
commit
6c7cecb943
21 changed files with 1025 additions and 396 deletions
191
SE_API/API.py
191
SE_API/API.py
|
@ -6,6 +6,7 @@ from GithubAPI.GithubAPI import GitHubAPI_Keys
|
|||
from google.appengine.ext import db
|
||||
import requests
|
||||
import uuid
|
||||
import datetime
|
||||
|
||||
from flask import Flask, request, render_template, redirect, abort, Response
|
||||
|
||||
|
@ -19,15 +20,23 @@ from models.Course import Course
|
|||
from models.Project import Project
|
||||
from models.Campus import Campus
|
||||
|
||||
#Validation Utils Libs
|
||||
# All API
|
||||
from SE_API.Validation_Utils import *
|
||||
from SE_API.Respones_Utils import *
|
||||
from SE_API.Email_Utils import *
|
||||
|
||||
from SE_API.UserRoutes import user_routes
|
||||
from SE_API.CampusRoutes import campus_routes
|
||||
from SE_API.CourseRoutes import course_routes
|
||||
from SE_API.ProjectRoutes import project_routes
|
||||
|
||||
|
||||
|
||||
|
||||
app = Flask(__name__, static_folder='../templates')
|
||||
|
||||
|
||||
|
||||
githubKeys = GitHubAPI_Keys()
|
||||
|
||||
app.config['GITHUB_CLIENT_ID'] = githubKeys.getId()
|
||||
|
@ -35,6 +44,12 @@ app.config['GITHUB_CLIENT_SECRET'] = githubKeys.getSecret()
|
|||
|
||||
github = GitHub(app)
|
||||
cross = CORS(app)
|
||||
|
||||
app.register_blueprint(user_routes)
|
||||
app.register_blueprint(campus_routes)
|
||||
app.register_blueprint(course_routes)
|
||||
app.register_blueprint(project_routes)
|
||||
|
||||
auto = Autodoc(app)
|
||||
|
||||
@app.errorhandler(404)
|
||||
|
@ -108,29 +123,28 @@ def send_activation(token):
|
|||
403 - Invalid Token<br>
|
||||
"""
|
||||
if not request.data:
|
||||
return Response(response=json.dumps({'message': 'Bad Request'}),
|
||||
status=400,
|
||||
mimetype="application/json")
|
||||
return bad_request()
|
||||
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")
|
||||
return forbidden("Not A Valid Token!")
|
||||
|
||||
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 bad_request()
|
||||
|
||||
return Response(status=200)
|
||||
|
||||
@app.route('/api/help')
|
||||
def documentation():
|
||||
return auto.html()
|
||||
return app.send_static_file('API_Doc/api_doc_index.html')
|
||||
|
||||
# @app.route('/api/help/campuses')
|
||||
# def documentation():
|
||||
# return auto.html()
|
||||
|
||||
@app.route('/home')
|
||||
def returnHome():
|
||||
|
@ -141,51 +155,6 @@ def returnHome():
|
|||
|
||||
|
||||
|
||||
@app.route('/api/getUserByToken/<string:token>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getUserByToken(token):
|
||||
'''
|
||||
<span class="card-title">This Function is will Activate a user and add tha campus to it</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- validation_token: 'seToken|email_suffix'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Example:<br>
|
||||
<code>
|
||||
{<br>
|
||||
'username' : 'github_username',<br>
|
||||
'name' : 'Bob Dylan',<br>
|
||||
'email' : 'email@domain.com',<br>
|
||||
'isLecturer' : true,<br>
|
||||
'seToken' : 'dds2d-sfvvsf-qqq-fdf33-sfaa',<br>
|
||||
'avatar_url' : 'http://location.domain.com/image.jpg',<br>
|
||||
'isFirstLogin' : false,<br>
|
||||
'campuses_id_list': ['22314','243512',...,'356'],<br>
|
||||
'classes_id_list': ['22314','243512',...,'356']<br>
|
||||
}
|
||||
</code>
|
||||
<br>
|
||||
403 - Invalid Token
|
||||
'''
|
||||
query = User.all()
|
||||
query.filter("seToken = ", token)
|
||||
|
||||
for u in query.run(limit=5):
|
||||
return Response(response=u.to_JSON(),
|
||||
status=201,
|
||||
mimetype="application/json") # Real response!
|
||||
|
||||
return Response(response=json.dumps({'message' : 'No User Found'}),
|
||||
status=400,
|
||||
mimetype="application/json")
|
||||
|
||||
|
||||
|
||||
@app.route('/githubOAuth')
|
||||
|
@ -229,114 +198,6 @@ def oauth(oauth_token):
|
|||
return cookieMonster(user.seToken)
|
||||
|
||||
|
||||
@app.route('/api/Campuses/create/<string:token>', methods=['POST'])
|
||||
@auto.doc()
|
||||
def create_campus(token):
|
||||
"""
|
||||
<span class="card-title">This call will create a new campus in the DB</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- JSON Object, Example: <br>
|
||||
{<br>
|
||||
'title': 'Campus name',<br>
|
||||
'email_ending': '@campus.ac.com',<br>
|
||||
'avatar_url': 'http://location.domain.com/image.jpg'<br>
|
||||
}<br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
201 - Created
|
||||
<br>
|
||||
403 - Invalid Token/Forbidden
|
||||
"""
|
||||
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=201,
|
||||
mimetype="application/json")
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route('/api/Campuses/<string:token>', methods=['GET'])
|
||||
@auto.doc()
|
||||
def get_campuses(token):
|
||||
"""
|
||||
<span class="card-title">This Call will return an array of all Campuses available</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE <br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Array, Example:<br>
|
||||
[<br>
|
||||
{
|
||||
'title': 'JCE',<br>
|
||||
'email_ending': '@post.jce.ac.il',<br>
|
||||
'master_user_id': 123453433341, (User that created the campus)<br>
|
||||
'avatar_url': 'http://some.domain.com/imagefile.jpg'<br>
|
||||
},<br>
|
||||
....<br>
|
||||
{<br>
|
||||
...<br>
|
||||
}req<br>
|
||||
]<br>
|
||||
<br>
|
||||
403 - Invalid Token<br>
|
||||
500 - 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')
|
||||
|
@ -385,3 +246,5 @@ def cookieMonster(uid):
|
|||
response = app.make_response(redirect_to_home )
|
||||
response.set_cookie('com.sehub.www',value=uid)
|
||||
return response
|
||||
|
||||
|
||||
|
|
144
SE_API/CampusRoutes.py
Normal file
144
SE_API/CampusRoutes.py
Normal file
|
@ -0,0 +1,144 @@
|
|||
__author__ = 'Aran'
|
||||
|
||||
from flask import Blueprint
|
||||
import json
|
||||
from GithubAPI.GithubAPI import GitHubAPI_Keys
|
||||
|
||||
from google.appengine.ext import db
|
||||
import requests
|
||||
import datetime
|
||||
|
||||
from flask import Flask, request, render_template, redirect, abort, Response
|
||||
|
||||
from flask.ext.github import GitHub
|
||||
from flask.ext.cors import CORS, cross_origin
|
||||
from flask.ext.autodoc import Autodoc
|
||||
|
||||
# DB Models
|
||||
from models.Campus import Campus
|
||||
|
||||
#Validation Utils Libs
|
||||
from SE_API.Validation_Utils import *
|
||||
from SE_API.Respones_Utils import *
|
||||
from SE_API.Email_Utils import *
|
||||
|
||||
|
||||
|
||||
campus_routes = Blueprint("campus_routes", __name__)
|
||||
auto = Autodoc()
|
||||
|
||||
@campus_routes.route('/api/campuses/create/<string:token>', methods=['POST'])
|
||||
@auto.doc()
|
||||
def create_campus(token):
|
||||
"""
|
||||
<span class="card-title">This call will create a new campus in the DB</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- JSON Object, Example: <br>
|
||||
{<br>
|
||||
'title': 'Campus name',<br>
|
||||
'email_ending': '@campus.ac.com',<br>
|
||||
'avatar_url': 'http://location.domain.com/image.jpg'<br>
|
||||
}<br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
201 - Created
|
||||
<br>
|
||||
403 - Invalid Token/Forbidden
|
||||
"""
|
||||
if not request.data:
|
||||
return bad_request()
|
||||
if not is_lecturer(token): #todo: change to lecturer id
|
||||
return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
#try to parse payload
|
||||
try:
|
||||
payload = json.loads(request.data)
|
||||
except Exception as e:
|
||||
return bad_request(e)
|
||||
|
||||
#check if name already exists
|
||||
try:
|
||||
query = Campus.all()
|
||||
query.filter("title = ", payload['title'])
|
||||
for c in query.run(limit=1):
|
||||
return forbidden("Campus with same name already exists")
|
||||
except Exception as e:
|
||||
print e
|
||||
|
||||
user = get_user_by_token(token)
|
||||
|
||||
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 bad_request()
|
||||
|
||||
|
||||
send_create_campus_request(user.email, user.name, campus.title)
|
||||
notify_se_hub_campus_request(campus, campus.title)
|
||||
return ok()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@campus_routes.route('/api/campuses/getAll/<string:token>', methods=['GET'])
|
||||
@auto.doc()
|
||||
def get_campuses(token):
|
||||
"""
|
||||
<span class="card-title">This Call will return an array of all Campuses available</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE <br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Array, Example:<br>
|
||||
[<br>
|
||||
{
|
||||
'title': 'JCE',<br>
|
||||
'email_ending': '@post.jce.ac.il',<br>
|
||||
'master_user_id': 123453433341, (User that created the campus)<br>
|
||||
'avatar_url': 'http://some.domain.com/imagefile.jpg'<br>
|
||||
},<br>
|
||||
....<br>
|
||||
{<br>
|
||||
...<br>
|
||||
}req<br>
|
||||
]<br>
|
||||
<br>
|
||||
403 - Invalid Token<br>
|
||||
"""
|
||||
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 forbidden("Invalid Token")
|
||||
|
||||
|
||||
|
||||
@campus_routes.route('/api/campuses/help')
|
||||
def documentation():
|
||||
return auto.html()
|
153
SE_API/CourseRoutes.py
Normal file
153
SE_API/CourseRoutes.py
Normal file
|
@ -0,0 +1,153 @@
|
|||
__author__ = 'Aran'
|
||||
|
||||
from flask import Blueprint
|
||||
import json
|
||||
from GithubAPI.GithubAPI import GitHubAPI_Keys
|
||||
|
||||
from google.appengine.ext import db
|
||||
import requests
|
||||
import datetime
|
||||
|
||||
from flask import Flask, request, render_template, redirect, abort, Response
|
||||
|
||||
from flask.ext.github import GitHub
|
||||
from flask.ext.cors import CORS, cross_origin
|
||||
from flask.ext.autodoc import Autodoc
|
||||
|
||||
# DB Models
|
||||
from models.Course import Course
|
||||
|
||||
#Validation Utils Libs
|
||||
from SE_API.Validation_Utils import *
|
||||
from SE_API.Respones_Utils import *
|
||||
|
||||
|
||||
|
||||
course_routes = Blueprint("course_routes", __name__)
|
||||
auto = Autodoc()
|
||||
|
||||
|
||||
@course_routes.route('/api/courses/create/<string:token>', methods=['POST'])
|
||||
@auto.doc()
|
||||
def create_course(token):
|
||||
"""
|
||||
<span class="card-title">This call will create a new course in the DB</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- JSON Object, Example: <br>
|
||||
{<br>
|
||||
'courseName': 'Advance Math',<br>
|
||||
'campusName': 'JCE',<br>
|
||||
'startDate': '2015-14-3'<br>
|
||||
'endDate': '2015-29-6'<br>
|
||||
'taskFlag': 'False'<br>
|
||||
}<br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
201 - Created
|
||||
<br>
|
||||
400 - Bad Request
|
||||
<br>
|
||||
403 - Invalid token or not a lecturer
|
||||
"""
|
||||
if not request.data:
|
||||
return bad_request()
|
||||
if not is_lecturer(token): #todo: change to lecturer id
|
||||
return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
user = get_user_by_token(token)
|
||||
|
||||
#try to parse payload
|
||||
try:
|
||||
payload = json.loads(request.data)
|
||||
except Exception as e:
|
||||
return bad_request(e)
|
||||
|
||||
|
||||
try:
|
||||
start_date = datetime.date(payload['startDate']['year'],payload['startDate']['month'],payload['startDate']['day'])
|
||||
end_date = datetime.date(payload['endDate']['year'],payload['endDate']['month'],payload['endDate']['day'])
|
||||
|
||||
if end_date <= start_date:
|
||||
return bad_request("end date cant be before (or same day) start date")
|
||||
|
||||
course = Course(courseName=payload['courseName'], campusName=payload['campusName'],
|
||||
startDate=start_date, endDate=end_date)
|
||||
|
||||
#check if name already exists
|
||||
try:
|
||||
query = Course.all()
|
||||
query.filter("courseName = ", payload['courseName'])
|
||||
for c in query.run(limit=1):
|
||||
return forbidden("Campus with same name already exists")
|
||||
except Exception as e:
|
||||
print e
|
||||
|
||||
|
||||
except Exception:
|
||||
return bad_request()
|
||||
|
||||
|
||||
|
||||
db.put(course)
|
||||
db.save
|
||||
return Response(response=course.to_JSON(),
|
||||
status=201,
|
||||
mimetype="application/json")
|
||||
|
||||
|
||||
|
||||
@course_routes.route('/api/courses/getCourseByCampusName/<string:name>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getCourseByCampusName(name):
|
||||
"""
|
||||
<span class="card-title">>This Call will return an array of all courses in a given campus</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- name: 'campus name'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Example:<br>
|
||||
<code>
|
||||
{<br>
|
||||
'courseName': 'Advance Math',<br>
|
||||
'campusName': 'JCE',<br>
|
||||
'startDate': '2015-14-3'<br>
|
||||
'endDate': '2015-29-6'<br>
|
||||
'taskFlag': 'False'<br>
|
||||
}
|
||||
</code>
|
||||
<br>
|
||||
"""
|
||||
arr = []
|
||||
query = Course.all()
|
||||
query.filter("campusName = ", name)
|
||||
|
||||
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")
|
||||
|
||||
|
||||
@course_routes.route('/api/courses/help')
|
||||
def documentation():
|
||||
return auto.html()
|
127
SE_API/Email_Utils.py
Normal file
127
SE_API/Email_Utils.py
Normal file
|
@ -0,0 +1,127 @@
|
|||
__author__ = 'sagi'
|
||||
|
||||
|
||||
from google.appengine.api import mail
|
||||
|
||||
|
||||
def send_validation_email(token, email, name):
|
||||
emailSuffix = str(email).split('@')[1]
|
||||
message = mail.EmailMessage(sender="SE-Hub Support <se-hub@appspot.gserviceaccount.com>",
|
||||
subject="SE-Hub Activate Account")
|
||||
|
||||
message.to = email
|
||||
|
||||
message.body = """
|
||||
Dear """+name+""":
|
||||
|
||||
To Activate your SE-Hub Account please click on the link below:<br>
|
||||
http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+"""
|
||||
to get access to your Campus :)
|
||||
|
||||
Please let us know if you have any questions.
|
||||
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
"""
|
||||
|
||||
message.html = """
|
||||
<html><head></head><body>
|
||||
<div>
|
||||
<center>
|
||||
<img src='https://cloud.githubusercontent.com/assets/2984053/6825467/7c9d0402-d303-11e4-9827-62a6d66f937a.png'>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
|
||||
</center>
|
||||
</div>
|
||||
<div style='width:70%'>
|
||||
<h1>Hey """+name+"""- Just one More Step...</h1>
|
||||
<h3>Dear """+name+""":</h3>
|
||||
|
||||
To Activate your SE-Hub Account please click on the link below:<br>
|
||||
http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+"""
|
||||
|
||||
to access you virtual class.
|
||||
</div>
|
||||
<br><br>
|
||||
Please let us know if you have any questions.
|
||||
<br>
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
message.send()
|
||||
|
||||
def send_create_campus_request(email, name, campus_name):
|
||||
message = mail.EmailMessage(sender="SE-Hub Support <se-hub@appspot.gserviceaccount.com>",
|
||||
subject="SE-Hub: "+campus_name+" Is Being Evaluated")
|
||||
|
||||
message.to = email
|
||||
|
||||
message.body = """
|
||||
Dear """+name+""":
|
||||
|
||||
Thank You For Choosing SE-Hub!
|
||||
Your Request for creating a new Campus named """+campus_name + """
|
||||
is Being Evaluated.
|
||||
You Will Receive an e-mail When We finish the process<br>
|
||||
|
||||
Please let us know if you have any questions.
|
||||
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
"""
|
||||
|
||||
message.html = """
|
||||
<html><head></head><body>
|
||||
<div>
|
||||
<center>
|
||||
<img src='https://cloud.githubusercontent.com/assets/2984053/6825467/7c9d0402-d303-11e4-9827-62a6d66f937a.png'>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
|
||||
</center>
|
||||
</div>
|
||||
<div style='width:70%'>
|
||||
<h1>Thank You For Choosing SE-Hub!</h1>
|
||||
<h3>Dear """+name+""":</h3>
|
||||
|
||||
Your Request for creating a new Campus named """+campus_name + """
|
||||
is Being Evaluated.
|
||||
You Will Receive an e-mail When We finish the process<br>
|
||||
|
||||
to access you virtual class.
|
||||
</div>
|
||||
<br><br>
|
||||
Please let us know if you have any questions.
|
||||
<br>
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
message.send()
|
||||
|
||||
|
||||
def notify_se_hub_campus_request(campus, campus_name):
|
||||
message = mail.EmailMessage(sender="SE-Hub Support <se-hub@appspot.gserviceaccount.com>",
|
||||
subject="SE-Hub: "+campus_name+" Is Being Evaluated")
|
||||
|
||||
message.to = 'se-hub@appspot.gserviceaccount.com'
|
||||
|
||||
message.body = """
|
||||
a new Campus request
|
||||
"""+str(campus.to_JSON())
|
||||
|
||||
message.html = """
|
||||
<html><head></head><body>
|
||||
<div>
|
||||
<center>
|
||||
<img src='https://cloud.githubusercontent.com/assets/2984053/6825467/7c9d0402-d303-11e4-9827-62a6d66f937a.png'>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
|
||||
</center>
|
||||
</div>
|
||||
<div style='width:70%'>
|
||||
<h1>New Campus!</h1>
|
||||
<br>
|
||||
""" + str(campus.to_JSON()) + """
|
||||
<br>
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
message.send()
|
134
SE_API/ProjectRoutes.py
Normal file
134
SE_API/ProjectRoutes.py
Normal file
|
@ -0,0 +1,134 @@
|
|||
__author__ = 'Aran'
|
||||
|
||||
from flask import Blueprint
|
||||
import json
|
||||
from GithubAPI.GithubAPI import GitHubAPI_Keys
|
||||
|
||||
from google.appengine.ext import db
|
||||
import requests
|
||||
import datetime
|
||||
|
||||
from flask import Flask, request, render_template, redirect, abort, Response
|
||||
|
||||
from flask.ext.github import GitHub
|
||||
from flask.ext.cors import CORS, cross_origin
|
||||
from flask.ext.autodoc import Autodoc
|
||||
|
||||
# DB Models
|
||||
from models.Project import Project
|
||||
|
||||
#Validation Utils Libs
|
||||
from SE_API.Validation_Utils import *
|
||||
from SE_API.Respones_Utils import *
|
||||
|
||||
|
||||
|
||||
project_routes = Blueprint("project_routes", __name__)
|
||||
auto = Autodoc()
|
||||
|
||||
@project_routes.route('/api/projects/create/<string:token>', methods=['POST'])
|
||||
@auto.doc()
|
||||
def create_project(token):
|
||||
"""
|
||||
<span class="card-title">This call will create a new project in the DB</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- JSON Object, Example: <br>
|
||||
{<br>
|
||||
'projectName': 'Advance Math',<br>
|
||||
'courseName': 'JCE',<br>
|
||||
'logo_url': 'http://location.domain.com/image.jpg'<br>
|
||||
'gitRepository': 'http://location.git.com/somthing'<br>
|
||||
}<br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
201 - Created
|
||||
<br>
|
||||
400 - Bad Request
|
||||
<br>
|
||||
403 - Invalid token or not a lecturer
|
||||
"""
|
||||
if not request.data:
|
||||
return bad_request()
|
||||
payload = json.loads(request.data)
|
||||
if not is_lecturer(token): #todo: change to lecturer id
|
||||
return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
user = get_user_by_token(token)
|
||||
|
||||
#todo: check legality
|
||||
|
||||
try:
|
||||
project = Project(projectName=payload['projectName'], courseName=payload['courseName'], masterId=user.key().id(), gitRepository=payload['gitRepository'], membersId=[token])
|
||||
except Exception as e:
|
||||
print e
|
||||
return bad_request()
|
||||
|
||||
db.put(project)
|
||||
db.save
|
||||
return Response(response=project.to_JSON(),
|
||||
status=201,
|
||||
mimetype="application/json")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@project_routes.route('/api/projects/getProjectsByCourseName/<string:name>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getProjectsByCourseName(name):
|
||||
"""
|
||||
<span class="card-title">>This Call will return an array of all projects in a given course</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- name: 'course name'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Example:<br>
|
||||
<code>
|
||||
{<br>
|
||||
'projectName': 'Advance Math',<br>
|
||||
'courseName': 'JCE',<br>
|
||||
'grade': 98,<br>
|
||||
'logo_url': 'http://location.domain.com/image.jpg',<br>
|
||||
'gitRepository': 'http://location.git.com/somthing',<br>
|
||||
'membersId': ['bob', 'dylan', 'quentin', 'terentino']<br>
|
||||
}
|
||||
</code>
|
||||
<br>
|
||||
"""
|
||||
|
||||
arr = []
|
||||
query = Project.all()
|
||||
query.filter("courseName = ", name)
|
||||
|
||||
for p in query.run():
|
||||
arr.append(dict(json.loads(p.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")
|
||||
|
||||
|
||||
|
||||
|
||||
@project_routes.route('/api/projects/help')
|
||||
def documentation():
|
||||
return auto.html()
|
|
@ -3,6 +3,29 @@ __author__ = 'Aran'
|
|||
from flask import Response
|
||||
import json
|
||||
|
||||
|
||||
def ok(message='OK'):
|
||||
return Response(response=json.dumps({'message': message}),
|
||||
status=200,
|
||||
mimetype="application/json")
|
||||
|
||||
def created(message='Created'):
|
||||
return Response(response=json.dumps({'message': message}),
|
||||
status=201,
|
||||
mimetype="application/json")
|
||||
|
||||
def accepted(message='Accepted'):
|
||||
return Response(response=json.dumps({'message': message}),
|
||||
status=202,
|
||||
mimetype="application/json")
|
||||
|
||||
|
||||
def no_content(message='No Content'):
|
||||
return Response(response=json.dumps({'message': message}),
|
||||
status=204,
|
||||
mimetype="application/json")
|
||||
|
||||
|
||||
def bad_request(message='Bad Request'):
|
||||
return Response(response=json.dumps({'message': message}),
|
||||
status=400,
|
||||
|
|
75
SE_API/UserRoutes.py
Normal file
75
SE_API/UserRoutes.py
Normal file
|
@ -0,0 +1,75 @@
|
|||
__author__ = 'Aran'
|
||||
|
||||
from flask import Blueprint
|
||||
import json
|
||||
from GithubAPI.GithubAPI import GitHubAPI_Keys
|
||||
|
||||
from google.appengine.ext import db
|
||||
import requests
|
||||
import datetime
|
||||
|
||||
from flask import Flask, request, render_template, redirect, abort, Response
|
||||
|
||||
from flask.ext.github import GitHub
|
||||
from flask.ext.cors import CORS, cross_origin
|
||||
from flask.ext.autodoc import Autodoc
|
||||
|
||||
# DB Models
|
||||
from models.User import User
|
||||
|
||||
#Validation Utils Libs
|
||||
from SE_API.Validation_Utils import *
|
||||
from SE_API.Respones_Utils import *
|
||||
|
||||
|
||||
user_routes = Blueprint("user_routes", __name__)
|
||||
auto = Autodoc()
|
||||
|
||||
|
||||
@user_routes.route('/api/users/getUserByToken/<string:token>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getUserByToken(token):
|
||||
"""
|
||||
<span class="card-title">>This Call will return a user by a given token</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Example:<br>
|
||||
<code>
|
||||
{<br>
|
||||
'username': 'DarkLord',<br>
|
||||
'name': 'Darth Vader',<br>
|
||||
'email': 'darkLord@death.planet,<br>
|
||||
'isLecturer': 'True',<br>
|
||||
'seToken': 'xxxxxx-xxxxx-xxxxx-xxxxxx',<br>
|
||||
'avatar_url': 'http://location.git.com/somthing'<br>
|
||||
'isFirstLogin': False,<br>
|
||||
'campuses_id_list': ['JCA','JCB','JCC'],<br>
|
||||
'classes_id_list': ['a','b','c']<br>
|
||||
}
|
||||
</code>
|
||||
<br>
|
||||
403 - No User Found
|
||||
"""
|
||||
query = User.all()
|
||||
query.filter("seToken = ", token)
|
||||
|
||||
for u in query.run(limit=5):
|
||||
return Response(response=u.to_JSON(),
|
||||
status=200,
|
||||
mimetype="application/json") # Real response!
|
||||
|
||||
return bad_request("No User Found")
|
||||
|
||||
|
||||
@user_routes.route('/api/users/help')
|
||||
def documentation():
|
||||
return auto.html()
|
|
@ -2,7 +2,7 @@ __author__ = 'sagi'
|
|||
from google.appengine.ext import db
|
||||
from models.User import User
|
||||
from models.Campus import Campus
|
||||
from google.appengine.api import mail
|
||||
|
||||
|
||||
|
||||
def get_user_by_token(token):
|
||||
|
@ -32,50 +32,3 @@ def is_lecturer(token):
|
|||
if user is None:
|
||||
return False
|
||||
return user.isLecturer
|
||||
|
||||
|
||||
def send_validation_email(token, email, name):
|
||||
emailSuffix = str(email).split('@')[1]
|
||||
message = mail.EmailMessage(sender="SE-Hub Support <se-hub@appspot.gserviceaccount.com>",
|
||||
subject="SE-Hub Activate Account")
|
||||
|
||||
message.to = email
|
||||
|
||||
message.body = """
|
||||
Dear """+name+""":
|
||||
|
||||
To Activate your SE-Hub Account please click on the link below:<br>
|
||||
http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+"""
|
||||
to get access to your Campus :)
|
||||
|
||||
Please let us know if you have any questions.
|
||||
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
"""
|
||||
|
||||
message.html = """
|
||||
<html><head></head><body>
|
||||
<div>
|
||||
<center>
|
||||
<img src='https://cloud.githubusercontent.com/assets/2984053/6825467/7c9d0402-d303-11e4-9827-62a6d66f937a.png'>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
|
||||
</center>
|
||||
</div>
|
||||
<div style='width:70%'>
|
||||
<h1>Hey """+name+"""- Just one More Step...</h1>
|
||||
<h3>Dear """+name+""":</h3>
|
||||
|
||||
To Activate your SE-Hub Account please click on the link below:<br>
|
||||
http://se-hub.appspot.com/api/validation/confirm/"""+token+"""|"""+emailSuffix+"""
|
||||
|
||||
to access you virtual class.
|
||||
</div>
|
||||
<br><br>
|
||||
Please let us know if you have any questions.
|
||||
<br>
|
||||
SE-Hub (c) 2015 niptop Team.
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
message.send()
|
||||
|
|
|
@ -17,20 +17,27 @@ class UserTestPlan(unittest.TestCase):
|
|||
print 'Initialized'
|
||||
|
||||
def test_getUserByToken_invalid(self):
|
||||
r = requests.get(self.__class__.url_+'api/getUserByToken/invalidtoken')
|
||||
self.assertEquals(r.status_code, 204)
|
||||
|
||||
r = requests.get(self.__class__.url_+'api/users/getUserByToken/invalidtoken')
|
||||
self.assertEquals(r.status_code, 403)
|
||||
|
||||
def test_getUserByToken_valid(self):
|
||||
r = requests.get(self.__class__.url_+'api/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
|
||||
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
|
||||
self.assertEquals(r.status_code, 200)
|
||||
self.assertEquals(r.json()['username'], 'qa_student')
|
||||
|
||||
|
||||
def test_getUserByToken_empty(self):
|
||||
r = requests.get(self.__class__.url_+'api/getUserByToken/')
|
||||
r = requests.get(self.__class__.url_+'api/users/getUserByToken/')
|
||||
self.assertEquals(r.status_code, 400)
|
||||
|
||||
def test_isStudent_Student(self):
|
||||
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
|
||||
self.assertEquals(r.status_code, 200)
|
||||
self.assertFalse(r.json()['isLecturer'])
|
||||
|
||||
def test_isLecturer_Lecturer(self):
|
||||
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER'])
|
||||
self.assertEquals(r.status_code, 200)
|
||||
self.assertTrue(r.json()['isLecturer'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -49,6 +49,9 @@
|
|||
<nav>
|
||||
<div class="nav-wrapper">
|
||||
<a href="#!" class="brand-logo center">SE-Hub API</a>
|
||||
<ul id="nav-mobile" class="left hide-on-med-and-down">
|
||||
<li><a href="/api/help">Home</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
|
|
|
@ -6,17 +6,25 @@ from google.appengine.ext import db
|
|||
class Course(db.Model):
|
||||
courseName = db.StringProperty(required=True)
|
||||
campusName = db.StringProperty(required=True)
|
||||
projects = db.StringListProperty(required=True)
|
||||
master_id = db.IntegerProperty(required=True)
|
||||
# projects = db.StringListProperty(required=True,default=[])
|
||||
startDate = db.DateProperty(required=True)
|
||||
endDate = db.DateProperty(required=False)
|
||||
taskFlag = db.BooleanProperty(required=True)
|
||||
endDate = db.DateProperty(required=True)
|
||||
|
||||
def to_JSON(self):
|
||||
data = {'courseName' : self.courseName,
|
||||
'campusName' : self.campusName,
|
||||
'projects' : self.projects,
|
||||
'startDate' : self.startDate,
|
||||
'endDate' : self.endDate,
|
||||
'taskFlag' : self.taskFlag,
|
||||
'master_id' : self.master_id,
|
||||
# 'projects' : self.projects,
|
||||
'startDate' : {
|
||||
'year': self.startDate.year,
|
||||
'month': self.startDate.month,
|
||||
'day': self.startDate.day,
|
||||
},
|
||||
'endDate' : {
|
||||
'year': self.endDate.year,
|
||||
'month': self.endDate.month,
|
||||
'day': self.endDate.day,
|
||||
}
|
||||
}
|
||||
return json.dumps(data)
|
||||
|
|
|
@ -5,13 +5,17 @@ from google.appengine.ext import db
|
|||
|
||||
class Project(db.Model):
|
||||
projectName = db.StringProperty(required=True)
|
||||
grade = db.IntegerProperty(required=True)
|
||||
logo_url = db.StringProperty(required=True)
|
||||
courseName = db.StringProperty(required=True)
|
||||
master_id = db.IntegerProperty(required=True)
|
||||
grade = db.IntegerProperty(required=True, default=0)
|
||||
logo_url = db.StringProperty(required=False)
|
||||
gitRepository = db.StringProperty(required=True)
|
||||
membersId = db.StringListProperty(required=True)
|
||||
|
||||
def to_JSON(self):
|
||||
data = {'projectName' : self.projectName,
|
||||
'courseName' : self.courseName,
|
||||
'master_id' : self.master_id,
|
||||
'grade' : self.grade,
|
||||
'logo_url' : self.logo_url,
|
||||
'gitRepository' : self.gitRepository,
|
||||
|
|
93
templates/API_Doc/api_doc_index.html
Normal file
93
templates/API_Doc/api_doc_index.html
Normal file
|
@ -0,0 +1,93 @@
|
|||
<html>
|
||||
<head>
|
||||
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/css/materialize.min.css">
|
||||
<!--Import jQuery before materialize.js-->
|
||||
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/js/materialize.min.js"></script>
|
||||
|
||||
<!--Let browser know website is optimized for mobile-->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
|
||||
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
|
||||
<title>
|
||||
SE-Hub API Docs
|
||||
</title>
|
||||
<style>
|
||||
|
||||
|
||||
div.mapping {
|
||||
margin: 20px 20px;
|
||||
}
|
||||
|
||||
ul.methods:before { content: "Methods: "; }
|
||||
ul.methods li {
|
||||
display: inline;
|
||||
list-style: none;
|
||||
}
|
||||
ul.methods li:after { content: ","; }
|
||||
ul.methods li:last-child:after { content: ""; }
|
||||
|
||||
ul.arguments:before { content: "Arguments: "; }
|
||||
ul.arguments li {
|
||||
display: inline;
|
||||
list-style: none;
|
||||
}
|
||||
ul.arguments .argument { font-style:italic }
|
||||
ul.arguments .default:not(:empty):before { content: "("; }
|
||||
ul.arguments .default:not(:empty):after { content: ")"; }
|
||||
ul.arguments li:after { content: ","; }
|
||||
ul.arguments li:last-child:after { content: ""; }
|
||||
|
||||
.docstring:before { content: "Description: "; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar-fixed">
|
||||
<nav>
|
||||
<div class="nav-wrapper">
|
||||
<a href="#!" class="brand-logo center">SE-Hub API</a>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<h1>
|
||||
SE-Hub Docs Index
|
||||
</h1>
|
||||
|
||||
|
||||
<div>
|
||||
<ul class="collection">
|
||||
<li class="collection-item dismissable"><div>Users Related API<a href="/api/users/help" class="secondary-content"><i class="mdi-content-send"></i></a></div></li>
|
||||
<li class="collection-item dismissable"><div>Campuses Related API<a href="/api/campuses/help" class="secondary-content"><i class="mdi-content-send"></i></a></div></li>
|
||||
<li class="collection-item dismissable"><div>Courses Related API<a href="/api/courses/help" class="secondary-content"><i class="mdi-content-send"></i></a></div></li>
|
||||
<li class="collection-item dismissable"><div>Validation Related API<a href="#!" class="secondary-content"><i class="mdi-content-send"></i></a></div></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<footer class="page-footer">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col l6 s12">
|
||||
<h5 class="white-text">Footer Content</h5>
|
||||
<p class="grey-text text-lighten-4">You can use rows and columns here to organize your footer content.</p>
|
||||
</div>
|
||||
<div class="col l4 offset-l2 s12">
|
||||
<h5 class="white-text">Links</h5>
|
||||
<ul>
|
||||
<li><a class="grey-text text-lighten-3" href="#!">Link 1</a></li>
|
||||
<li><a class="grey-text text-lighten-3" href="#!">Link 2</a></li>
|
||||
<li><a class="grey-text text-lighten-3" href="#!">Link 3</a></li>
|
||||
<li><a class="grey-text text-lighten-3" href="#!">Link 4</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer-copyright">
|
||||
<div class="container">
|
||||
SE-Hub (c) 2015 Niptop Team
|
||||
<a class="grey-text text-lighten-4 right" href="#!">More Links</a>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
|
@ -15,9 +15,18 @@ md-list .md-button {
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
.welcome-logo-banner{
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Using Data-URI converted from svg until <md-icon> becomes available
|
||||
https://github.com/google/material-design-icons
|
||||
*/
|
||||
|
||||
p {
|
||||
margin-left: 2em;
|
||||
}
|
||||
|
||||
.menuBtn {
|
||||
background: transparent url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMjRweCIgaGVpZ2h0PSIyNHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDI0IDI0IiB4bWw6c3BhY2U9InByZXNlcnZlIj4KPGcgaWQ9IkhlYWRlciI+CiAgICA8Zz4KICAgICAgICA8cmVjdCB4PSItNjE4IiB5PSItMjIzMiIgZmlsbD0ibm9uZSIgd2lkdGg9IjE0MDAiIGhlaWdodD0iMzYwMCIvPgogICAgPC9nPgo8L2c+CjxnIGlkPSJMYWJlbCI+CjwvZz4KPGcgaWQ9Ikljb24iPgogICAgPGc+CiAgICAgICAgPHJlY3QgZmlsbD0ibm9uZSIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0Ii8+CiAgICAgICAgPHBhdGggZD0iTTMsMThoMTh2LTJIM1YxOHogTTMsMTNoMTh2LTJIM1YxM3ogTTMsNnYyaDE4VjZIM3oiIHN0eWxlPSJmaWxsOiNmM2YzZjM7Ii8+CiAgICA8L2c+CjwvZz4KPGcgaWQ9IkdyaWQiIGRpc3BsYXk9Im5vbmUiPgogICAgPGcgZGlzcGxheT0iaW5saW5lIj4KICAgIDwvZz4KPC9nPgo8L3N2Zz4=) no-repeat center center;
|
||||
}
|
||||
|
@ -54,19 +63,15 @@ body.noscroll
|
|||
}
|
||||
|
||||
.avatar {
|
||||
float: left;
|
||||
margin-top: 1em;
|
||||
margin-right: 1em;
|
||||
position: relative;
|
||||
position: center;
|
||||
|
||||
-webkit-border-radius: 30%;
|
||||
-moz-border-radius: 30%;
|
||||
border-radius: 30%;
|
||||
|
||||
|
||||
-webkit-border-radius: 50%;
|
||||
-moz-border-radius: 50%;
|
||||
border-radius: 50%;
|
||||
|
||||
-webkit-box-shadow: 0 0 0 3px #fff, 0 0 0 4px #999, 0 2px 5px 4px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: 0 0 0 3px #fff, 0 0 0 4px #999, 0 2px 5px 4px rgba(0,0,0,.2);
|
||||
box-shadow: 0 0 0 3px #fff, 0 0 0 4px #999, 0 2px 5px 4px rgba(0,0,0,.2);
|
||||
}
|
||||
|
||||
/*.avatar {
|
||||
|
@ -75,9 +80,13 @@ body.noscroll
|
|||
|
||||
.avatar img {
|
||||
border-radius: 40px;
|
||||
position:center;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
margin: 6px; /*centers the image in the parent element */
|
||||
-webkit-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);
|
||||
-moz-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);
|
||||
box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);
|
||||
}
|
||||
|
||||
/* Added BY devMatan */
|
||||
|
@ -92,22 +101,22 @@ body.noscroll
|
|||
|
||||
}*/
|
||||
|
||||
.campusAvatar:
|
||||
.campusAvatar img
|
||||
{
|
||||
float: left;
|
||||
/*
|
||||
margin-top: 1em;
|
||||
margin-right: 1em;
|
||||
position: relative;
|
||||
width:70%;
|
||||
height:auto;
|
||||
position: center;
|
||||
*/
|
||||
|
||||
-webkit-border-radius: 50%;
|
||||
-moz-border-radius: 50%;
|
||||
border-radius: 50%;
|
||||
|
||||
-webkit-box-shadow: 0 0 0 3px #fff, 0 0 0 4px #999, 0 2px 5px 4px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: 0 0 0 3px #fff, 0 0 0 4px #999, 0 2px 5px 4px rgba(0,0,0,.2);
|
||||
box-shadow: 0 0 0 3px #fff, 0 0 0 4px #999, 0 2px 5px 4px rgba(0,0,0,.2);
|
||||
border-radius: 40px;
|
||||
position:center;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
margin: 6px;
|
||||
-webkit-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);
|
||||
-moz-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);
|
||||
box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);
|
||||
}
|
||||
|
||||
.spacer{
|
||||
|
@ -131,7 +140,7 @@ body.noscroll
|
|||
float:right;
|
||||
}*/
|
||||
|
||||
/*.dropDown: /* TODO *
|
||||
/*.dropDown /* TODO *
|
||||
{
|
||||
border-bottom: 2px black solid;
|
||||
border-top: 2px black solid;
|
||||
|
@ -139,15 +148,3 @@ body.noscroll
|
|||
border-right: 2px black solid;
|
||||
border-radius: 1px black solid;
|
||||
}*/
|
||||
|
||||
|
||||
/*
|
||||
h1
|
||||
{
|
||||
position:center;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<div class="wellcome-float">
|
||||
<center style="background-color:rgba(225,225,225,.8); padding: 15px">
|
||||
<div width="70%">
|
||||
<img src="https://cloud.githubusercontent.com/assets/2984053/6825467/7c9d0402-d303-11e4-9827-62a6d66f937a.png">
|
||||
<img src="https://cloud.githubusercontent.com/assets/2984053/6825467/7c9d0402-d303-11e4-9827-62a6d66f937a.png" class="welcome-logo-banner">
|
||||
</div>
|
||||
</center>
|
||||
<h3>Wellcome To SE-Hub!</h3>
|
||||
|
@ -35,7 +35,7 @@
|
|||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-route.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-animate.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular-aria.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-aria.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-cookies.js"></script>
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.8.3/angular-material.min.js"></script>
|
||||
|
|
|
@ -14,8 +14,10 @@ welcome.controller('welcomeController', ['$scope', 'apiService', '$cookies', '$w
|
|||
console.log("Welcome Controller");
|
||||
|
||||
var uid = $cookies['com.sehub.www'];
|
||||
if(uid)
|
||||
if(uid){
|
||||
console.info("Session in Place");
|
||||
$window.location.href = DEBUG ? 'http://localhost:8080/home' : 'http://se-hub.appspot.com/home';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -26,8 +28,7 @@ app.config(['$routeProvider', '$locationProvider',
|
|||
function($routeProvider, $locationProvider) {
|
||||
$routeProvider
|
||||
.when('/', {
|
||||
templateUrl: 'templates/views/home.html',
|
||||
controller: 'mainController'
|
||||
templateUrl: 'templates/views/home.html'
|
||||
})
|
||||
.when('/register', {
|
||||
templateUrl: 'templates/views/register.html',
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
angular.module('SeHub')
|
||||
.controller('mainController', ['$scope', '$rootScope', 'apiService', '$cookies', '$location', function ($scope, $rootScope, apiService, $cookies, $location) {
|
||||
|
||||
$rootScope.seToken = $cookies['com.sehub.www'];
|
||||
var token = $rootScope.seToken;
|
||||
var token = $cookies['com.sehub.www'];
|
||||
|
||||
$scope.loadingData = true;
|
||||
$scope.isInRegisterMode = false;
|
||||
|
||||
apiService.getUserByToken(token).success(function(data){
|
||||
console.log(data);
|
||||
if(data.message == 'No User Found')
|
||||
if(data.message == 'No User Found'){
|
||||
console.error("No User Found!");
|
||||
}
|
||||
|
||||
$scope.user = data;
|
||||
$rootScope.user = data;
|
||||
if($scope.user.isFirstLogin)
|
||||
if($scope.user.isFirstLogin){
|
||||
$scope.menuObj = {};
|
||||
$scope.isInRegisterMode = true;
|
||||
$scope.loadingData = false;
|
||||
$location.path('/register')
|
||||
}
|
||||
})
|
||||
|
||||
$scope.loadingData = false;
|
||||
|
|
|
@ -1,45 +1,37 @@
|
|||
angular.module('SeHub')
|
||||
.controller('registerController', ['$scope', '$location', '$cookies', 'apiService', '$rootScope', function ($scope, $location, $cookies, apiService ,$rootScope) {
|
||||
|
||||
.controller('registerController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function ($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope)
|
||||
{
|
||||
$scope.userHasNoName = false;
|
||||
$scope.campusChecked = false;
|
||||
$scope.isEmpty = true; // if the academic email line is empty
|
||||
// $scope.fullMail = $scope.academicEmail + $scope.campusObj.email_ending; // Will hold the full academic email of the user
|
||||
|
||||
$rootScope.seToken = $cookies['com.sehub.www'];
|
||||
var token = $rootScope.seToken;
|
||||
|
||||
apiService.getUserByToken(token).success(function(data){
|
||||
apiService.getUserByToken(token).success(function(data) // Get user token
|
||||
{
|
||||
$scope.user = data;
|
||||
console.log(data);
|
||||
|
||||
if(data.message == 'No User Found')
|
||||
console.error("No User Found!");
|
||||
console.log(data);
|
||||
|
||||
$scope.user = data;
|
||||
$rootScope.user = data;
|
||||
if($scope.user.isFirstLogin)
|
||||
$location.path('/register')
|
||||
|
||||
|
||||
if($scope.user.name === ";"){
|
||||
if($scope.user.name === ";")
|
||||
{
|
||||
$scope.user.name = "";
|
||||
$scope.user.name = $scope.user.username
|
||||
$scope.userHasNoName = true;
|
||||
}
|
||||
|
||||
apiService.getAllCampuses($scope.user.seToken).success(function(data)
|
||||
apiService.getAllCampuses($scope.user.seToken).success(function(data) // Get all the campuses
|
||||
{
|
||||
$scope.campuses = data;
|
||||
}).error(function()
|
||||
{
|
||||
// TODO
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
$scope.dropdownClicked = function()
|
||||
{
|
||||
if($scope.campus){
|
||||
|
@ -51,40 +43,61 @@ angular.module('SeHub')
|
|||
console.log($scope.campusObj); // TODO REMOVE!!
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
$scope.submitClicked = function()
|
||||
$scope.submitClicked = function(ev)
|
||||
{
|
||||
console.log($scope.user.AcMail);
|
||||
$scope.mail = 'pin';
|
||||
console.log($scope.mail);
|
||||
};
|
||||
|
||||
|
||||
|
||||
apiService.getAllCampuses($scope.user.seToken).success(function(data)
|
||||
if($scope.user.AcMail != null)
|
||||
{
|
||||
$scope.campuses = data;
|
||||
var fullMail = $scope.user.AcMail + $scope.campusObj.email_ending; // Holds the full academic email of the user
|
||||
apiService.sendValidationMail($scope.user.seToken, fullMail).success(function(data)
|
||||
{
|
||||
console.log("DONE - 200");
|
||||
$mdDialog.show($mdDialog.alert().title('E-mail Verification').content('A verification e-mail has been sent to your email address.')
|
||||
.ariaLabel('Email verification alert dialog').ok('Got it!').targetEvent(ev)); // Pop-up alert for e-mail verification
|
||||
$cookieStore.remove("com.sehub.www"); // Removing the cookies
|
||||
$window.location.href = 'http://se-hub.appspot.com'; // Reference to 'welcome' page
|
||||
}).error(function()
|
||||
{
|
||||
// TODO
|
||||
$mdDialog.show($mdDialog.alert().title('Error - E-mail Verification').content('An error has occured in your e-mail address.')
|
||||
.ariaLabel('Email verification error alert dialog').ok('Got it!').targetEvent(ev));
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
// apiService.sendValidationMail($scope.user.seToken, $scope.fullMail).success(function(data) // TODO: Add 2nd parameter email type Email
|
||||
$scope.lecturerPrivilege = function(data)
|
||||
{
|
||||
// console.log("Now " + data);
|
||||
var isLecturer;
|
||||
if(!data) // if i am a lecturer (when pressing -> getting last data value before pressing) = "!data" => I Am Lecturer
|
||||
{
|
||||
isLecturer = true;
|
||||
console.log("im lecturer " + isLecturer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO FOR LATER - toast
|
||||
// TODO FOR LATER
|
||||
|
||||
// $scope.getPopWindowPosition = function()
|
||||
// {
|
||||
// console.log($scope.fullMail);
|
||||
// console.log("200");
|
||||
|
||||
// // TODO
|
||||
// }).error(function()
|
||||
// return Object.keys($scope.toastPosition).filter(function(pos)
|
||||
// {
|
||||
// return $scope.toastPosition[pos];
|
||||
// }).join(' ');
|
||||
// };
|
||||
|
||||
// });
|
||||
|
||||
|
||||
|
||||
// $scope.toastPosition =
|
||||
// {
|
||||
// bottom: false,
|
||||
// top: true,
|
||||
// left: false,
|
||||
// right: true
|
||||
// };
|
||||
|
||||
// TODO FOR LATER
|
||||
// TODO FOR LATER
|
||||
|
||||
}]);
|
|
@ -7,7 +7,7 @@ service.factory('apiService', ['$http', function($http) {
|
|||
|
||||
return {
|
||||
getUserByToken: function(token){
|
||||
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/getUserByToken/" + token;
|
||||
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/users/getUserByToken/" + token;
|
||||
req = {
|
||||
method : "GET",
|
||||
url : url
|
||||
|
@ -16,7 +16,7 @@ service.factory('apiService', ['$http', function($http) {
|
|||
return $http(req);
|
||||
},
|
||||
getAllCampuses: function(token){
|
||||
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/Campuses/" + token;
|
||||
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/campuses/getAll/" + token;
|
||||
req = {
|
||||
method : "GET",
|
||||
url : url
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
<link rel="stylesheet" href="templates/css/theme.css">
|
||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1" />
|
||||
</head>
|
||||
<!-- <body layout="column" ng-controller="RegisterCtrl"> -->
|
||||
<body layout="column" >
|
||||
|
||||
<body layout="column" ng-controller="mainController">
|
||||
<md-toolbar layout="row">
|
||||
<button ng-click="toggleSidenav('left')" hide-gt-sm class="menuBtn">
|
||||
<span class="visually-hidden">Menu</span>
|
||||
|
@ -23,8 +23,28 @@
|
|||
<md-sidenav layout="column" class="md-sidenav-left md-whiteframe-z2" md-component-id="left" md-is-locked-open="$mdMedia('gt-sm')">
|
||||
<md-content>
|
||||
<center>
|
||||
<h1>Menu</h1>
|
||||
<h1><i class="fa fa-compass"></i> Menu</h1>
|
||||
</center>
|
||||
<div ng-if="loadingData">
|
||||
<md-progress-circular></md-progress-circular>
|
||||
</div>
|
||||
<div ng-if="isInRegisterMode"> <!-- User Needs To Register -->
|
||||
<md-card layout-padding>
|
||||
<div layout=-"row">
|
||||
<div class="spacer"></div>
|
||||
<div>
|
||||
<h3>
|
||||
<i class="fa fa-exclamation-triangle"></i>
|
||||
</h3>
|
||||
</div>
|
||||
<div class="spacer"></div>
|
||||
</div>
|
||||
<p>
|
||||
You Are Currently Not Assigned To Any Campus Nor Course.
|
||||
Please Fill The Form On your Right Hand Side, and Confirm Your Academic E-Mail.
|
||||
</p>
|
||||
</md-card>
|
||||
</div>
|
||||
</md-content>
|
||||
</md-sidenav>
|
||||
<div layout="column" flex id="content">
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
<div class="register">
|
||||
<md-content layout-padding>
|
||||
<md-card layout-padding>
|
||||
<h1 style="margin-left:15px"><i class="fa fa-pencil"></i> Registration</h1>
|
||||
<md-card class="wellcome-float" style="margin-top: 15px;">
|
||||
<center>
|
||||
<p>First Login Of {{user.name}}</p>
|
||||
First Login Of {{user.name}}
|
||||
<div class="avatar">
|
||||
<img ng-src="{{user.avatar_url}}" alt="{{item.who}}" style="position:center !important;"/>
|
||||
<img ng-src="{{user.avatar_url}}" alt="{{item.who}}">
|
||||
</div>
|
||||
</center>
|
||||
<br><br>
|
||||
<div layout="col">
|
||||
<div>
|
||||
<md-input-container ng-if="userHasNoName">
|
||||
|
@ -16,10 +15,20 @@
|
|||
<input ng-model="user.name" required>
|
||||
</md-input-container>
|
||||
</div>
|
||||
<br></br>
|
||||
<div layout="row" layout-align="center center">
|
||||
Are You A Lecturer?
|
||||
<md-switch ng-model="user.isLecturer" aria-label="Switch 1">
|
||||
<p>Are You A Lecturer?</p>
|
||||
<md-switch ng-click = "lecturerPrivilege(data.cb1)" ng-model="data.cb1" aria-label="Switch 1">
|
||||
Switch 1: {{ data.cb1 }}
|
||||
<div ng-if="data">
|
||||
<!-- <md-progress-circular class="md-hue-2" md-mode="indeterminate">
|
||||
</md-progress-circular> -->
|
||||
</div>
|
||||
</md-switch>
|
||||
|
||||
<!-- TODO original -->
|
||||
<!-- <md-switch class="md-primary" md-no-ink aria-label="Switch No Ink" ng-model="data.cb5">
|
||||
</md-switch> -->
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
|
@ -28,7 +37,8 @@
|
|||
<md-option ng-repeat="c in campuses" value="{{c.title}}">{{c.title}}</md-option>
|
||||
</md-select>
|
||||
</div>
|
||||
<div layout="col">
|
||||
</div>
|
||||
<div layout="col" layout-align="center center">
|
||||
<div>
|
||||
<div class="campusAvatar" ng-if="campusChecked">
|
||||
<img ng-src="{{campusObj.avatar_url}}" alt="campusAvatar">
|
||||
|
@ -37,8 +47,7 @@
|
|||
</div>
|
||||
<div>
|
||||
<div class = "disabledSubmitButton">
|
||||
<md-button ng-click="submitClicked()" ng-disabled="!campusChecked" class="md-raised md-primary">Submit</md-button>
|
||||
</div>
|
||||
<md-button ng-click="submitClicked($event)" ng-disabled="!campusChecked" class="md-raised md-primary">Submit</md-button>
|
||||
</div>
|
||||
</div>
|
||||
<div layout="row" layout-align="center center">
|
||||
|
@ -62,8 +71,6 @@
|
|||
But Choose Now for easy Registration...
|
||||
</p>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</md-card>
|
||||
</md-content>
|
||||
|
|
Loading…
Reference in a new issue