Permalink
Browse files

Add Client.

  • Loading branch information...
lepture committed Nov 21, 2013
1 parent d1e3b6d commit 3f1c8f2f86b408be6105593c3206cad814dfcb73
Showing with 54 additions and 1 deletion.
  1. +54 −1 app.py
View
55 app.py
@@ -2,8 +2,9 @@
from flask import Flask
from flask import session, request
from flask import render_template, redirect
from flask import render_template, redirect, jsonify
from flask_sqlalchemy import SQLAlchemy
from werkzeug.security import gen_salt
app = Flask(__name__, template_folder='templates')
@@ -20,6 +21,37 @@ class User(db.Model):
username = db.Column(db.String(40), unique=True)
class Client(db.Model):
client_id = db.Column(db.String(40), primary_key=True)
client_secret = db.Column(db.String(55), nullable=False)
user_id = db.Column(db.ForeignKey('user.id'))
user = db.relationship('User')
_redirect_uris = db.Column(db.Text)
_default_scopes = db.Column(db.Text)
@property
def client_type(self):
return 'public'
@property
def redirect_uris(self):
if self._redirect_uris:
return self._redirect_uris.split()
return []
@property
def default_redirect_uri(self):
return self.redirect_uris[0]
@property
def default_scopes(self):
if self._default_scopes:
return self._default_scopes.split()
return []
def current_user():
if 'id' in session:
uid = session['id']
@@ -41,6 +73,27 @@ def home():
user = current_user()
return render_template('home.html', user=user)
@app.route('/client')
def client():
user = current_user()
if not user:
return redirect('/')
item = Client(
client_id=gen_salt(40),
client_secret=gen_salt(50),
_redirect_uris='http://localhost:8000/authorized',
_default_scopes='email',
user_id=user.id,
)
db.session.add(item)
db.session.commit()
return jsonify(
client_id=item.client_id,
client_secret=item.client_secret,
)
if __name__ == '__main__':
db.create_all()
app.run()

0 comments on commit 3f1c8f2

Please sign in to comment.