Created
April 16, 2013 16:41
-
-
Save nuwansh/5397465 to your computer and use it in GitHub Desktop.
Custom devise Strategy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#require 'devise/strategies/authenticatable' | |
module SubdomainAuthenticatable | |
# Default strategy for signing in a user, based on his email and password in the database. | |
class CustomStrategy < Devise::Strategies::Authenticatable | |
def authenticate! | |
resource = valid_password? && mapping.to.joins(:company).where(authentication_hash.merge({:companies => {:subdomain => "test"}})).first | |
return fail(:not_found_in_database) unless resource | |
if validate(resource){ resource.valid_password?(password) } | |
resource.after_database_authentication | |
success!(resource) | |
end | |
end | |
end | |
end | |
Warden::Strategies.add(:subdomain_authenticatable, SubdomainAuthenticatable::CustomStrategy) | |
Devise.add_module(:subdomain_authenticatable, | |
:strategy => true, | |
:controller => :sessions, | |
:route => :session | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment