diff options
author | Alexander Sulfrian <alex@spline.inf.fu-berlin.de> | 2014-11-18 05:53:03 +0100 |
---|---|---|
committer | Alexander Sulfrian <alex@spline.inf.fu-berlin.de> | 2014-11-19 02:15:56 +0100 |
commit | 2e7f70591ddc2e73be3e9d426ceaffaf3df0b9c2 (patch) | |
tree | 4c97732f4d0295d382aa666f1585dc7f7c626ad9 | |
parent | 7936b83766edbf70321851bc02c96fae620a9e88 (diff) | |
download | padlite-teams-2e7f70591ddc2e73be3e9d426ceaffaf3df0b9c2.tar.gz padlite-teams-2e7f70591ddc2e73be3e9d426ceaffaf3df0b9c2.tar.bz2 padlite-teams-2e7f70591ddc2e73be3e9d426ceaffaf3df0b9c2.zip |
auth: fix auth/redirect if app is hosted in subdir
-rw-r--r-- | auth.py | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -1,11 +1,13 @@ from flask_peewee.auth import Auth -from flask import session +from flask_peewee.utils import get_next +from flask import session, url_for, request, redirect from models import User, Session from app import app, db, pad from datetime import datetime from padlite import APIException import ldap import uuid +import functools class LdapAuth(Auth): def get_user_model(self): @@ -70,4 +72,17 @@ class LdapAuth(Auth): return reduce(escape, chars_to_escape, s) -auth = LdapAuth(app, db, user_model=User) + def test_user(self, test_fn): + def decorator(fn): + @functools.wraps(fn) + def inner(*args, **kwargs): + user = self.get_logged_in_user() + + if not user or not test_fn(user): + login_url = url_for('%s.login' % self.blueprint.name, next="%s%s" % (request.environ['SCRIPT_NAME'], get_next())) + return redirect(login_url) + return fn(*args, **kwargs) + return inner + return decorator + +auth = LdapAuth(app, db, user_model=User, default_next_url='/teams') |