Another (perhaps better?) approach is to see the devise models generated as the accounts and not the users.
$ devise UserAccount
$ devise AdminAccount
These accounts would/could then have the username and password
Then generate a "normal" User model, but without username and password. Then a user could have different credentials when logging into a specific account, fx for the Admin account a higher security requirement for the password and so on.
For this to work, you would have to use the account API methods, such as user_account_can? (already available)
This method requires a current_user_account method to be available.
You could generate these methods like this:
::CanTango.config.user_accounts.registered.each do |account|
base.class_eval %{
def current_#{account}_account
current_{account}
end
}
end
Now the current_user_account method will proxy to current_user.
There is also a method session_user available, which will retrieve the current_user if present (logged in), and fall back to the guest_user.
def guest_user
CanTango.config.guest.user
end
Now when using user_can?, the correct implementation would have to figure out that the current_user method returns an account instance and not a user in this setup. It should in this case call the #user method on this account (from session) to get the user instance. I will try to implement this functionality tonight!
Hell it is a bit complicated to cover all the most common scenarios!
Feel free to come up with more suggestions. The project is best developed with feedback from various developers using it!
Kris