views:

81

answers:

1

Hi guys,
I am using devise as my authentication system. And i want to authenticate user with username along with subdomain. It seems that devise needs both the username and subdomain field in the same table which is not in my case.
I have subdomain field in Company table while username and password in the UserAccount table.
And there is references_many relation between UserAccount and Company table Now how can i authenticate the user with both username and subdomain

Please help me out.

A: 
!#user.rb
devise :all, :authentication_keys => [:email, :subdomain]

OR

!#config/initializer/devise.rb
Devise.setup do |config|
  config.authentication_keys = [ :email, :subdomain ]
end

!#login.erb.html
...
f.hidden_field :subdomain, :value => current_subdomain
...

!#user.rb
def self.find_for_authentication(conditions={})
  find(:first, :conditions => { :companies => { :subdomain => conditions.delete(:subdomain) } }, :joins => :companies)
end
satish