2010-11-19 81 views

回答

38

我發現這非常有幫助的片段在this thread在色器件谷歌組

初始化/ some_initializer.rb:

Warden::Strategies.add(:custom_strategy_name) do 
    def valid? 
    # code here to check whether to try and authenticate using this strategy; 
    return true/false 
    end 

    def authenticate! 
    # code here for doing authentication; 
    # if successful, call 
    success!(resource) # where resource is the whatever you've authenticated, e.g. user; 
    # if fail, call 
    fail!(message) # where message is the failure message 
    end 
end 

添加下列初始化/ devise.rb

config.warden do |manager| 
    manager.default_strategies.unshift :custom_strategy_name 
    end 
+1

感謝,非常有用,我用它來驗證我的舊網站的joomla用戶:-) – simo 2012-12-20 18:52:48

+0

非常有幫助的答案,但鏈接被破壞。你能糾正它嗎? – mrzasa 2013-01-23 11:28:11

+1

鏈接仍然適用於我。 – opsb 2013-01-23 12:49:57