1234567891011121314151617181920212223242526272829303132 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # **************************************************************************
- # Copyright © 2017 jianglin
- # File Name: app.py
- # Author: jianglin
- # Email: xiyang0807@gmail.com
- # Created: 2017-03-28 16:11:07 (CST)
- # Last Update:星期二 2017-3-28 16:11:19 (CST)
- # By:
- # Description:
- # **************************************************************************
- from flask_principal import RoleNeed, UserNeed, identity_loaded
- from flask_login import current_user
- def register_app(app):
- @identity_loaded.connect_via(app)
- def on_identity_loaded(sender, identity):
- '''基础权限'''
- identity.user = current_user
- if hasattr(current_user, 'id'):
- identity.provides.add(UserNeed(current_user.id))
- if hasattr(current_user, 'is_superuser'):
- if current_user.is_superuser:
- identity.provides.add(RoleNeed('super'))
- if hasattr(current_user, 'is_authenticated'):
- if current_user.is_authenticated:
- identity.provides.add(RoleNeed('auth'))
|