Skip to content

Instantly share code, notes, and snippets.

@nuwansh
Created April 16, 2013 16:41
Show Gist options
  • Save nuwansh/5397465 to your computer and use it in GitHub Desktop.
Save nuwansh/5397465 to your computer and use it in GitHub Desktop.
Custom devise Strategy
#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