Created
September 2, 2014 20:06
-
-
Save jdanielnd/d7cc71ada585057df9f3 to your computer and use it in GitHub Desktop.
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 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