2010-11-19 31 views

Trả lời

38

tôi thấy đoạn này rất hữu ích trong this thread vào nhóm devise google

initializers/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 

add sau để initializers/devise.rb

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

cảm ơn, rất hữu ích, tôi đã sử dụng nó để xác thực người dùng Joomla của trang web cũ của tôi :-) – simo

+0

Câu trả lời rất hữu ích, liên kết bị hỏng mặc dù. Bạn có thể sửa nó không? – mrzasa

+1

Liên kết vẫn hoạt động với tôi. – opsb

Các vấn đề liên quan