2010-11-19 82 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