blob: 626057e9dfb0e0fede5e134bf0757e48b335fa89 [file] [log] [blame]
from functools import wraps
from flask import current_app, url_for
from flask_login import current_user
from werkzeug.utils import redirect
__author__ = 'hanl'
def secured(func):
'''
overriding login_required, but redirects to login, not to unauthorized page
:param func:
:return:
'''
@wraps(func)
def decorated_view(*args, **kwargs):
if current_app.login_manager._login_disabled:
return func(*args, **kwargs)
elif not current_user.is_authenticated():
# fixme: how to set next?
# request.args.get('next') or
return redirect(url_for('.login'))
return func(*args, **kwargs)
return decorated_view