Cleaning some code and Packages

Moving the API to a Package.
added 404 page
removed some methods
This commit is contained in:
Sagi Dayan 2015-05-09 22:52:30 +03:00
parent 25ba685516
commit 7684936631
12 changed files with 317 additions and 118 deletions

130
SE_API/API.py Normal file
View file

@ -0,0 +1,130 @@
__author__ = 'sagi'
import json
from GithubAPI.GithubAPI import GitHubAPI_Keys
from google.appengine.ext import db
import requests
import uuid
from flask import Flask, request, render_template, redirect, abort
# from User import User
from flask.ext.github import GitHub
from flask.ext.cors import CORS, cross_origin
app = Flask(__name__, static_folder='../templates')
githubKeys = GitHubAPI_Keys()
app.config['GITHUB_CLIENT_ID'] = githubKeys.getId()
app.config['GITHUB_CLIENT_SECRET'] = githubKeys.getSecret()
github = GitHub(app)
cross = CORS(app)
@app.errorhandler(404)
def page_not_found(e):
return app.send_static_file('views/404/index.html')
@app.route('/')
def wellcomePage():
return app.send_static_file('index.html')
@app.route('/home')
def returnHome():
try:
return app.send_static_file('views/index.html')
except Exception:
abort(404)
@app.route('/api/getUserByToken/<string:token>', methods=["GET"])
def getUserByToken(token):
query = User.all()
query.filter("seToken = ", token)
for u in query.run(limit=5):
return u.to_JSON()
return json.loads({'message' : 'No User Found'}), 403
@app.route('/githubOAuth')
@cross_origin('*')
@github.authorized_handler
def oauth(oauth_token):
if oauth_token is None:
return render_template("index.html", messages={'error': 'OAuth Fail'})
try:
response = requests.get("https://api.github.com/user?access_token=" + oauth_token)
user_data = json.loads(response.content)
response = requests.get("https://api.github.com/user/emails?access_token=" + oauth_token)
userEmails = json.loads(response.content)
except Exception:
return "<h1>Max Retries connection To Github</h1><p>github has aborted connection due to to many retries. you need to wait</p>"
resault = User.all()
resault.filter("username =", str(user_data["login"]))
print user_data["login"]
for u in resault.run(limit=5):
print "Exists!!!"
u.seToken = str(uuid.uuid4())
u.accessToken = oauth_token
u.put()
return cookieMonster(u.seToken)
if user_data["name"] == "":
tempName = ";"
else:
tempName = user_data["name"]
if user_data["email"] == "":
for email in userEmails:
if email["primary"] and email["verified"]:
tempEmail = email["email"]
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('/login')
@cross_origin('*')
def login():
return github.authorize()
def cookieMonster(uid):
redirect_to_home = redirect('/home')
response = app.make_response(redirect_to_home )
response.set_cookie('com.sehub.www',value=uid)
return response
class User(db.Model):
username = db.StringProperty(required=True)
name = db.StringProperty(required=True)
email = db.StringProperty(required=True)
isLecturer = db.BooleanProperty(required=True)
accsessToken = db.StringProperty(required=True)
seToken = db.StringProperty(required=True)
avatar_url = db.StringProperty(required=True)
isFirstLogin = db.BooleanProperty(default=True)
def to_JSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
sort_keys=True, indent=4)

BIN
SE_API/API.pyc Normal file

Binary file not shown.

1
SE_API/__init__.py Normal file
View file

@ -0,0 +1 @@
__author__ = 'sagi'

BIN
SE_API/__init__.pyc Normal file

Binary file not shown.

120
main.py
View file

@ -1,122 +1,6 @@
import json
from GithubAPI.GithubAPI import GitHubAPI_Keys
from SE_API import API
from google.appengine.ext import db
import requests
import uuid
from flask import Flask, request, render_template, redirect
# from User import User
from flask.ext.github import GitHub
from flask.ext.cors import CORS, cross_origin
app = Flask(__name__, static_folder='templates')
githubKeys = GitHubAPI_Keys()
app.config['GITHUB_CLIENT_ID'] = githubKeys.getId()
app.config['GITHUB_CLIENT_SECRET'] = githubKeys.getSecret()
github = GitHub(app)
cross = CORS(app)
@app.route('/')
def wellcomePage():
return app.send_static_file('index.html')
@app.route('/home')
def returnHome():
return app.send_static_file('views/index.html')
@app.route('/api/getUserByToken/<string:token>', methods=["GET"])
def getUserByToken(token):
query = User.all()
query.filter("seToken = ", token)
for u in query.run(limit=5):
return u.to_JSON()
return json.loads({'message' : 'No User Found'})
@app.route('/githubOAuth')
@cross_origin('*')
@github.authorized_handler
def oauth(oauth_token):
if oauth_token is None:
return render_template("index.html", messages={'error': 'OAuth Fail'})
response = requests.get("https://api.github.com/user?access_token=" + oauth_token)
user_data = json.loads(response.content)
response = requests.get("https://api.github.com/user/emails?access_token=" + oauth_token)
userEmails = json.loads(response.content)
resault = User.all()
resault.filter("username =", str(user_data["login"]))
print user_data["login"]
for u in resault.run(limit=5):
print "Exists!!!"
u.seToken = str(uuid.uuid4())
u.accessToken = oauth_token
u.put()
return cookieMonster(u.seToken)
if user_data["name"] == "":
tempName = ";"
else:
tempName = user_data["name"]
if user_data["email"] == "":
for email in userEmails:
if email["primary"] and email["verified"]:
tempEmail = email["email"]
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('/login')
@cross_origin('*')
def login():
return github.authorize()
def cookieMonster(uid):
redirect_to_home = redirect('/home')
response = app.make_response(redirect_to_home )
response.set_cookie('com.sehub.www',value=uid)
return response
class User(db.Model):
username = db.StringProperty(required=True)
name = db.StringProperty(required=True)
email = db.StringProperty(required=True)
isLecturer = db.BooleanProperty(required=True)
accsessToken = db.StringProperty(required=True)
seToken = db.StringProperty(required=True)
avatar_url = db.StringProperty(required=True)
isFirstLogin = db.BooleanProperty(default=True)
def to_JSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
sort_keys=True, indent=4)
app = API.app
if __name__ == '__main__':
app.run()

BIN
main.pyc

Binary file not shown.

View file

@ -0,0 +1,158 @@
/* reset */
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,dl,dt,dd,ol,nav ul,nav li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline;}
article, aside, details, figcaption, figure,footer, header, hgroup, menu, nav, section {display: block;}
ol,ul{list-style:none;margin:0px;padding:0px;}
blockquote,q{quotes:none;}
blockquote:before,blockquote:after,q:before,q:after{content:'';content:none;}
table{border-collapse:collapse;border-spacing:0;}
/* start editing from here */
a{text-decoration:none;}
.txt-rt{text-align:right;}/* text align right */
.txt-lt{text-align:left;}/* text align left */
.txt-center{text-align:center;}/* text align center */
.float-rt{float:right;}/* float right */
.float-lt{float:left;}/* float left */
.clear{clear:both;}/* clear float */
.pos-relative{position:relative;}/* Position Relative */
.pos-absolute{position:absolute;}/* Position Absolute */
.vertical-base{ vertical-align:baseline;}/* vertical align baseline */
.vertical-top{ vertical-align:top;}/* vertical align top */
.underline{ padding-bottom:5px; border-bottom: 1px solid #eee; margin:0 0 20px 0;}/* Add 5px bottom padding and a underline */
nav.vertical ul li{ display:block;}/* vertical menu */
nav.horizontal ul li{ display: inline-block;}/* horizontal menu */
img{max-width:100%;}
/*end reset*
*/
body{
background: url(../images/bg1.png);
font-family: "Century Gothic",Arial, Helvetica, sans-serif;
}
.content p{
margin: 18px 0px 45px 0px;
}
.content p{
font-family: "Century Gothic";
font-size:2em;
color:#666;
text-align:center;
}
.content p span,.logo h1 a{
color:#e54040;
}
.content{
text-align:center;
padding:115px 0px 0px 0px;
}
.content a{
color:#fff;
font-family: "Century Gothic";
background: #666666; /* Old browsers */
background: -moz-linear-gradient(top, #666666 0%, #666666 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#666666), color-stop(100%,#666666)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #666666 0%,#666666 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #666666 0%,#666666 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #666666 0%,#666666 100%); /* IE10+ */
background: linear-gradient(to bottom, #666666 0%,#666666 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#666666', endColorstr='#666666',GradientType=0 ); /* IE6-9 */
padding: 15px 20px;
border-radius: 1em;
}
.content a:hover{
color:#e54040;
}
.logo{
text-align:center;
-webkit-box-shadow: 0 8px 6px -6px rgb(97, 97, 97);
-moz-box-shadow: 0 8px 6px -6px rgb(97, 97, 97);
box-shadow: 0 8px 6px -6px rgb(97, 97, 97);
}
.logo h1{
font-size:2em;
font-family: "Century Gothic";
background: #666666; /* Old browsers */
background: -moz-linear-gradient(top, #666666 0%, #666666 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#666666), color-stop(100%,#666666)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #666666 0%,#666666 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #666666 0%,#666666 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #666666 0%,#666666 100%); /* IE10+ */
background: linear-gradient(to bottom, #666666 0%,#666666 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#666666', endColorstr='#666666',GradientType=0 ); /* IE6-9 */
padding: 10px 10px 18px 10px;
}
.logo h1 a{
font-size:1em;
}
.copy-right{
padding-top:20px;
}
.copy-right p{
font-size:0.9em;
}
.copy-right p a{
background:none;
color:#e54040;
padding:0px 0px 5px 0px;
font-size:0.9em;
}
.copy-right p a:hover{
color:#666;
}
/*------responive-design--------*/
@media screen and (max-width: 1366px) {
.content {
padding: 58px 0px 0px 0px;
}
}
@media screen and (max-width:1280px) {
.content {
padding: 58px 0px 0px 0px;
}
}
@media screen and (max-width:1024px) {
.content {
padding: 58px 0px 0px 0px;
}
.content p {
font-size: 1.5em;
}
.copy-right p{
font-size:0.9em;
}
}
@media screen and (max-width:640px) {
.content {
padding: 58px 0px 0px 0px;
}
.content p {
font-size: 1.3em;
}
.copy-right p{
font-size:0.9em;
}
}
@media screen and (max-width:460px) {
.content {
padding:20px 0px 0px 0px;
margin:0px 12px;
}
.content p {
font-size:0.9em;
}
.copy-right p{
font-size:0.8em;
}
}
@media screen and (max-width:320px) {
.content {
padding:30px 0px 0px 0px;
margin:0px 12px;
}
.content a {
padding:10px 15px;
font-size:0.8em;
}
.content p {
margin: 18px 0px 22px 0px;
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

View file

@ -0,0 +1,26 @@
<html>
<head>
<title>0hh Website Template | Home :: W3layouts</title>
<meta name="keywords" content="404 iphone web template, Andriod web template, Smartphone web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
<link href="templates/views/404/css/style.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<div class="header">
<div class="logo">
<h1><a href="#">SE-Hub Says: "Ohhhh.... :( "</a></h1>
</div>
</div>
<div class="content">
<img src="templates/views/404/images/error-img.png" title="error" />
<p><span><label>O</label>hh.....</span>You Requested the page that is no longer There.</p>
<a href="#">Back To Home</a>
</div>
</div>
</body>
</html>