Skip to content

Commit

Permalink
Load token_user before requests
Browse files Browse the repository at this point in the history
  • Loading branch information
whtsky committed Jul 5, 2014
1 parent 1c36e91 commit af13960
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 1 addition & 7 deletions gather/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,5 @@


def need_auth(**kw):
from gather.account.models import Account
token = request.headers.get("token", None)
user = None
if token:
user = Account.query.filter_by(api_token=token).first()
if not user:
if not g.token_user:
raise ProcessingException(description='Not Authorized', code=401)
g.token_user = user
9 changes: 8 additions & 1 deletion gather/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

BASEDIR = os.path.dirname(os.path.abspath(__file__))

from flask import Flask, g
from flask import Flask, g, request
from flask.ext.turbolinks import turbolinks
from jinja2 import MemcachedBytecodeCache
from gather.extensions import db, assets, mail, cache, api_manager
Expand Down Expand Up @@ -64,6 +64,13 @@ def register_hooks(app):
@app.before_request
def load_user():
g.user = get_current_user()
from gather.account.models import Account

token = request.headers.get("token", None)
if token:
g.token_user = Account.query.filter_by(api_token=token).first()
else:
g.token_user = None


def register_jinja(app):
Expand Down

0 comments on commit af13960

Please sign in to comment.