2

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.

g.gatos
  • 21
  • 2
  • Does this answer your question? [Implementing Flask-Login with multiple User Classes](https://stackoverflow.com/questions/15871391/implementing-flask-login-with-multiple-user-classes) – cizario Jul 02 '20 at 21:09
  • Hello and thanks for your effort to help me. I have seen this. It refer to roles authorization and not 2 logins systems that I am I need. I came with my own solution which I will post so0n for future reference. – g.gatos Jul 08 '20 at 07:55

0 Answers0