Guest User

Untitled

a guest
Feb 15th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. def requires_permission(permission):
  2. def decorator(function):
  3. def decorated_function(*args, **kwargs):
  4. if not current_user.is_authenticated:
  5. return redirect('/auth/login')
  6. elif not getattr(current_user.permissions, permission):
  7. return "you need to be an admin", 401
  8. else:
  9. return function(*args, **kwargs)
  10. return decorated_function
  11. return decorator
  12.  
  13. @bp.route('/')
  14. @requires_permission('admin')
  15. def dashboard(company=None):
  16. return "Hello, World!"
  17.  
  18. return redirect(url_for('main.dashboard', company = company))
Add Comment
Please, Sign In to add comment