I need your help, i want to use the same login page ( site/login ) to authenicate two different type of user ( Customer and Employee ), Customer and Employee are two separated table in database.
So if someone knows how to do it, i’ll be very glad.
You need to modify the authenticate() method of your UserIdentity component. Instead of using one model (one table) to check for login access, check both tables.
As a side note I think you should not have your customers and employees in separate tables. They should be in one user table and one column that says what type of user they are.
Thank you guys for your fast responses. Unfortunately, in specifications book, i have to separate Employee model and Customer model ( There is many fields not in commen between them).
So if someone has an idea to make this possible, it’s gonna be very helpful for me.
I don’t see any difficulties with it. nkd already described how to make authentication against two models. Anything else should also leverage both models (e.g. users sign up, user validation, etc.) same way.
keep users as lean as possible so you can keep the users in memory for scaling
id
username/email
password
name
other common fields i.e. name
type (I.e. 1 / 2 / 3 or employee / customer
Employees
user_id ( i would make this the users id)
other not common fields
or
id
user_id (index)
other not common fields (for normalization)
Customer
user_id ( i would make this the users id)
other not common fields
or
id
user_id (index)
other not common fields (for normalization)
you would check the login against the user table. You could set the after login to redirect to either customer page or employee page based on the value in the user table type.
It would be quite slow and difficult to scale if you where checking multiple tables on the same login.