You could use a dropdownlist/radiobuttonlist to select the type of user you want to authenticate. Depending on the selected type, you could then perform different authentication methods in your UserIdentity class.
So roughly i’d start with something like this:
Add a dropdownlist to your login view, to select the user type
Add a public var $userType to your UserIdentity
Use a scenario in LoginForm for every user type and configure the validation rules for each
In the login action of your controller, check the value of your dropdownlist and set the model scenario accordingly
In the authenticate method of LoginForm set the usertype in UserIdentity according to your scenario
Perform different authentication in UserIdentity depending on the user type
It’s just the basic concept, but i hope it helps to get started.
Hmm, Mike there stays a problem with your way of doing and Yii.
I feel that Yii inforces us to use a User table which is intended to gather information login of users.
–
Your hint works perfectly however we MUST put in User ALL informations which is used to login.
if a User1 needs only username and passwd and User2 need extra information as birth date (for instance), then we HAVE to add a column (birth date) to our User global table.
But this field is not used for User1.
(I hop I’m clear enough)
Other problem with this User "Yii predefined table" (even if we can change the fields in this table and changing username by email, we MUST gather login info in it for ALL users) is that in case we have, during loging process, search on a huge table (because collecting all users).
In my application, depending on url we know which kind of user must be login and recognize and then we search (or we would like to search, due to Yii architecture I don’t know whether it is possible ) in the good table.
Actually i don’t really understand. UserIdentity allows to do any kind of authentication you can think of. Yii doesn’t limit you there. It also doesn’t force you to fill in all fields all the time. That’s what scenarios are for. And why would it be a problem that for some user types, some unused columns (birthdate) are empty? Maybe you can explain and give a (simplified) example of some concrete user attributes?
I have Admin who is able to log in with (email, password)
I have Customer who is able to log in with (email, password)
I have Guest who is able to log in with (email, password, special-code)
There is 3 specific areas in the application
One dedicated to Admin, one for Customer and one for Guest
One chooses his specific area and connects with a specific login form representing their login information.
Then I judged ok to have at leat 2 different models (tables)
one for Admin/Customer
one for Guest. The amount of Guest is far higher than amount of Customers
Then at login stages searching in a single user table which encompasses admin, customer, guest seems to me time consuming and not so consistent because special-code addresses guests and not Admin nor Customer.
And As far As I have understood (but I’m far for this I think) Yii proposes user table.
(one table, one model)
Maybe I’m totaly wrong in my perception of the problem also…
So use 2 models, e.g. User (for Customer/Admin) and Guest. Then in UserIdentity use the above $userType to decide, which model to use for authentication.