0

I am using Flask-Login in my application. I have been using it for one class (User) but in my new project I will have ProductOwner class and Customer class. Records of those classes will login but I couldn't figure out how to do it.

I found a similar question at Implementing Flask-Login with multiple User Classes page but it's solution is with roles.My two classes have different fields.

Can you please explain how should I do it ?

Thank you

Community
  • 1
  • 1
Burak Nebioglu
  • 71
  • 2
  • 11
  • The function you use as your `user_loader` will need some way to distinguish between the different user classes. That function, though, can return an instance of any class you want, so long as it adheres to the interface required by Flask-Login for a user. – dirn Oct 07 '14 at 19:01
  • Thank you dirn I will try to have a solution by trying user_loader I hope I can solve. – Burak Nebioglu Oct 07 '14 at 20:05

1 Answers1

0

You could have your ProductOwner class and your Customer class inherit from a "User" base class. Put all of the authentication / user-loading logic in the User class.

Dan Cauley
  • 178
  • 1
  • 8
  • Sorry for not mentioning about this I am a beginner at Flask and I am using Flask-Sqlalchemy my classes are my database models. I did not try before what you say. Can you please write a simple code to show how it works. Thank you very much Dan. – Burak Nebioglu Oct 07 '14 at 22:49
  • @BurakNebioglu take a look at the Python docs on class inheritance, which will explain subclassing: https://docs.python.org/3/tutorial/classes.html and flask-sqlalchemy docs: flask-sqlalchemy.palletsprojects.com – monsieuralfonse64 Sep 30 '20 at 18:21