Skip to content

Instantly share code, notes, and snippets.

@jdanielnd
Created September 2, 2014 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdanielnd/d7cc71ada585057df9f3 to your computer and use it in GitHub Desktop.
Save jdanielnd/d7cc71ada585057df9f3 to your computer and use it in GitHub Desktop.
require 'devise/strategies/authenticatable'
module Devise
module Strategies
class MixedAuthenticatable < Authenticatable
def authenticate!
authenticator.authenticate!
end
private
def authenticator
authenticator_factory.new(@env, @scope)
end
def authenticator_factory
if user_requires_ldap_authentication
LdapAuthenticatable
else
DatabaseAuthenticatable
end
end
def user_requires_ldap_authentication
if user = User.find_by_email(email)
user.organization_requires_ldap?
else
false
end
end
def email
user_params[:email]
end
def user_params
params[:user]
end
end
end
end
Warden::Strategies.add(:mixed_authenticatable, Devise::Strategies::MixedAuthenticatable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment