diff --git a/SE_API/API.py b/SE_API/API.py new file mode 100644 index 0000000..776d7bb --- /dev/null +++ b/SE_API/API.py @@ -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/', 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 "

Max Retries connection To Github

github has aborted connection due to to many retries. you need to wait

" + + 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) \ No newline at end of file diff --git a/SE_API/API.pyc b/SE_API/API.pyc new file mode 100644 index 0000000..9e0a22d Binary files /dev/null and b/SE_API/API.pyc differ diff --git a/SE_API/__init__.py b/SE_API/__init__.py new file mode 100644 index 0000000..066a6b3 --- /dev/null +++ b/SE_API/__init__.py @@ -0,0 +1 @@ +__author__ = 'sagi' diff --git a/SE_API/__init__.pyc b/SE_API/__init__.pyc new file mode 100644 index 0000000..dc74950 Binary files /dev/null and b/SE_API/__init__.pyc differ diff --git a/main.py b/main.py index 96d2560..7ceb8e5 100644 --- a/main.py +++ b/main.py @@ -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/', 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() \ No newline at end of file diff --git a/main.pyc b/main.pyc index fb857c1..b5a8909 100644 Binary files a/main.pyc and b/main.pyc differ diff --git a/templates/views/404/css/style.css b/templates/views/404/css/style.css new file mode 100644 index 0000000..b25b4f5 --- /dev/null +++ b/templates/views/404/css/style.css @@ -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; + } +} \ No newline at end of file diff --git a/templates/views/404/images/Thumbs.db b/templates/views/404/images/Thumbs.db new file mode 100644 index 0000000..ad1abc6 Binary files /dev/null and b/templates/views/404/images/Thumbs.db differ diff --git a/templates/views/404/images/bg.png b/templates/views/404/images/bg.png new file mode 100644 index 0000000..2fc1dba Binary files /dev/null and b/templates/views/404/images/bg.png differ diff --git a/templates/views/404/images/bg1.png b/templates/views/404/images/bg1.png new file mode 100644 index 0000000..77e81bb Binary files /dev/null and b/templates/views/404/images/bg1.png differ diff --git a/templates/views/404/images/error-img.png b/templates/views/404/images/error-img.png new file mode 100644 index 0000000..5826dd3 Binary files /dev/null and b/templates/views/404/images/error-img.png differ diff --git a/templates/views/404/index.html b/templates/views/404/index.html new file mode 100644 index 0000000..e0bff5a --- /dev/null +++ b/templates/views/404/index.html @@ -0,0 +1,26 @@ + + + + 0hh Website Template | Home :: W3layouts + + + + + + +
+ +

hh.....You Requested the page that is no longer There.

+ Back To Home + +
+ + + + + +