I would like to change the default Flask-Login @login_required
so that it will check a database as to whether a user is banned or not.
I am aware I could create a custom decorator to check my database and add it to all my views, however this would be less useful due to the number of views I have; it wouldn't be convenient.
Is this possible or not? Thanks.
You can use the next approach:
from flask.ext.login import LoginManager
@login_manager.user_loader
def load_user_if_not_banned(user_id):
user = ... # Load user from DB
return user if not user.is_banned else None
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With