Does Flask-Login not support roles?
Does Flask-Login not support roles?
If not, are there any projects that have added this feature to Flask-Login? Otherwise, it appears to be a bit daunting to migrate from Flask-Login to Flask-User. Otherwise, is there any sort of direction out there for migrating from Flask-Login to Flask-User?
Unfortunately, that project is no longer supported and after installing Flask-Permissions via pip, it does not recognize the Github page's suggested import.
– user1995565
Sep 12 '18 at 2:02
you might want to check Flask Security, which has support for roles
– gittert
Sep 12 '18 at 13:53
1 Answer
1
Again, answering my own question here for anyone else curious how you can add the feature of handling multiple roles while still using Flask-Login. I created the below decorator which just checks the current_user.role to see if it is "Admin". You should also check the same thing when letting the user log in, depending on if they are logging in to the admin or the user panel.
from functools import wraps
def admin_required(f):
@wraps(f)
def wrap(*args, **kwargs):
if current_user.role == "Admin":
return f(*args, **kwargs)
else:
flash("You need to be an admin to view this page.")
return redirect(url_for('index'))
return wrap
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
github.com/raddevon/flask-permissions
– Mad Wombat
Sep 11 '18 at 22:41