app.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # **************************************************************************
  4. # Copyright © 2017 jianglin
  5. # File Name: app.py
  6. # Author: jianglin
  7. # Email: xiyang0807@gmail.com
  8. # Created: 2017-03-28 16:11:07 (CST)
  9. # Last Update:星期二 2017-3-28 16:11:19 (CST)
  10. # By:
  11. # Description:
  12. # **************************************************************************
  13. from flask_principal import RoleNeed, UserNeed, identity_loaded
  14. from flask_login import current_user
  15. def register_app(app):
  16. @identity_loaded.connect_via(app)
  17. def on_identity_loaded(sender, identity):
  18. '''基础权限'''
  19. identity.user = current_user
  20. if hasattr(current_user, 'id'):
  21. identity.provides.add(UserNeed(current_user.id))
  22. if hasattr(current_user, 'is_superuser'):
  23. if current_user.is_superuser:
  24. identity.provides.add(RoleNeed('super'))
  25. if hasattr(current_user, 'is_authenticated'):
  26. if current_user.is_authenticated:
  27. identity.provides.add(RoleNeed('auth'))