syrusakbary / Flask-SuperAdmin

The best admin interface framework for Flask. With scaffolding for MongoEngine, Django and SQLAlchemy.
Other
641 stars 134 forks source link

Need a way to use flask-security wrapped flask-login #23

Open davidthewatson opened 11 years ago

davidthewatson commented 11 years ago

Hi, I'm using flask superadmin and I like what I see. However, I need admin views to be protected. I'm using flask-security with mongoengine. Is there a way that I can get the admin to be protected using the flask-login from flask-security?

The typical method is to use the login_required decorator which can be used directly:

@login_required

or in class-based views such as:

from flask.views import MethodView
from flask_security import login_required

class ListView(MethodView):
    decorators = [login_required]

Thanks!

wojcikstefan commented 11 years ago

Hi @davidthewatson, I know this issue's been open for a long time, but perhaps you can still use some help.

I'd just use the flask-admin's current_user and create my own admin class inheriting from flask-superadmin's Admin, e.g. class ProtectedAdmin(Admin) and override is_accessible:

from flask.ext.login import current_user

class ProtectedAdmin(Admin):
    def is_accessible(self):
        return current_user.is_authenticated()  # + extra code for permissions

If it's not an issue for you any more, would you consider closing the ticket?