Use blueprints for apps
This commit is contained in:
parent
ede6fcfaf9
commit
51594687e2
@ -402,7 +402,6 @@ def logout():
|
|||||||
|
|
||||||
@app.route('/auth/login_callback')
|
@app.route('/auth/login_callback')
|
||||||
def login_callback():
|
def login_callback():
|
||||||
print(flask.session)
|
|
||||||
if 'login_next' in flask.session and flask.session['login_next']:
|
if 'login_next' in flask.session and flask.session['login_next']:
|
||||||
return flask.redirect(flask.session['login_next'])
|
return flask.redirect(flask.session['login_next'])
|
||||||
else:
|
else:
|
||||||
@ -443,7 +442,7 @@ def email_authenticate():
|
|||||||
|
|
||||||
for app_name in app.config['APPS']:
|
for app_name in app.config['APPS']:
|
||||||
app_main = importlib.import_module(app_name + '.main')
|
app_main = importlib.import_module(app_name + '.main')
|
||||||
app_main.main(app)
|
app.register_blueprint(app_main.blueprint)
|
||||||
|
|
||||||
# === Model-Views ===
|
# === Model-Views ===
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Eos - Verifiable elections
|
# Eos - Verifiable elections
|
||||||
# Copyright © 2017 RunasSudo (Yingtong Li)
|
# Copyright © 2017-18 RunasSudo (Yingtong Li)
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -23,7 +23,18 @@ from eos.redditauth.election import *
|
|||||||
import base64
|
import base64
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
def main(app):
|
blueprint = flask.Blueprint('eosweb.redditauth', __name__)
|
||||||
|
|
||||||
|
app = None
|
||||||
|
oauth = None
|
||||||
|
reddit = None
|
||||||
|
|
||||||
|
@blueprint.record
|
||||||
|
def reddit_register(setup_state):
|
||||||
|
global app, oauth, reddit
|
||||||
|
|
||||||
|
app = setup_state.app
|
||||||
|
|
||||||
oauth = OAuth()
|
oauth = OAuth()
|
||||||
reddit = oauth.remote_app('Reddit',
|
reddit = oauth.remote_app('Reddit',
|
||||||
request_token_url=None,
|
request_token_url=None,
|
||||||
@ -39,15 +50,15 @@ def main(app):
|
|||||||
consumer_secret=app.config['REDDIT_OAUTH_CLIENT_SECRET']
|
consumer_secret=app.config['REDDIT_OAUTH_CLIENT_SECRET']
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.route('/auth/reddit/login')
|
|
||||||
def reddit_login():
|
|
||||||
return reddit.authorize(callback=app.config['BASE_URI'] + flask.url_for('reddit_oauth_authorized'), state=uuid.uuid4())
|
|
||||||
|
|
||||||
@reddit.tokengetter
|
@reddit.tokengetter
|
||||||
def get_reddit_oauth_token():
|
def get_reddit_oauth_token():
|
||||||
return (flask.session.get('user').oauth_token, '')
|
return (flask.session.get('user').oauth_token, '')
|
||||||
|
|
||||||
@app.route('/auth/reddit/oauth_callback')
|
@blueprint.route('/auth/reddit/login')
|
||||||
|
def reddit_login():
|
||||||
|
return reddit.authorize(callback=app.config['BASE_URI'] + flask.url_for('eosweb.redditauth.reddit_oauth_authorized'), state=uuid.uuid4())
|
||||||
|
|
||||||
|
@blueprint.route('/auth/reddit/oauth_callback')
|
||||||
def reddit_oauth_authorized():
|
def reddit_oauth_authorized():
|
||||||
resp = reddit.authorized_response()
|
resp = reddit.authorized_response()
|
||||||
if resp is None:
|
if resp is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user