I am on a flask-learning path basically for personal entertainment. I've done many simple applications in the recent past some of them are on production right now.
I cannot find anywhere an answer to my question which is: What is the best practice when an flask application needs to supply both user login and admin login, for example:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_admin import Admin
from flask_login import LoginManager, login_required
from flask_admin import Admin
app = Flask(__name__)
db = SQLAlchemy(app)
login_manager = LoginManager(app)
admin=Admin(app)
class User(db.Model):
pass
class Member(db.Model):
pass
@login_manager.user_loader
def load_user(user_id):
return User.query.filter_by_(id=int(user_id)).first()
@app.route("/user_area")
@login_required
def user_area():
return "something only a user can see"
#how to have another login processed for admin view
admin.add_view(ModelView(User,db.session))
app.run()
What i need is how to separate login process for user_area and admin views. I want one login system to use User Class and the other Member class.
I could develop a custom login system and some decorators but I am afraid I would trade off security.
I want to better understand the best practices and developing patterns so I am open to educational suggestions.
Thank you very much.