Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

about user authentication with username and subdomain

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.

like image 622
Gagan Avatar asked Jan 21 '23 17:01

Gagan


1 Answers

!#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
like image 182
Satish Avatar answered Jan 31 '23 11:01

Satish