blueprint.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:redberry 作者: michaelcho 项目源码 文件源码
def admin_login_required(method):
    def is_admin(user):
        if isinstance(user.is_admin, bool):
            return user.is_admin
        else:
            return user.is_admin()

    @functools.wraps(method)
    def wrapper(*args, **kwargs):
        if not current_user.is_authenticated:
            flash("This section is for logged in users only.", 'warning')
            return redirect(url_for('redberry.home'))

        if not hasattr(current_user, 'is_admin'):
            flash("Redberry expects your user instance to implement an `is_admin` boolean attribute "
                  "or an `is_admin()` method.", 'warning')
            return redirect(url_for('redberry.home'))

        if not is_admin(current_user):
            flash("This section is for admin users only.", 'warning')
            return redirect(url_for('redberry.home'))

        return method(*args, **kwargs)

    return wrapper


############
# CMS ROUTES
############
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号