2012-05-17 46 views
1

我在我的Rails 3.0.10應用程序中使用authlogic和omniauth進行身份驗證。 但是,當我從omniauth提供程序獲取回調時,我無法創建新的用戶會話以便登錄該用戶。在authlogic中創建沒有密碼的新用戶會話

other responses(甚至在authlogic docs),它說,使用UserSession.create(@user, true)應該能夠建立並堅持一個新的會話。

但是,這並不適用於我。它只適用於@user在數據庫中有密碼(通過直接在db中插入密碼)。

但使用第三方身份驗證提供程序時沒有密碼,因此我無法登錄用戶。

任何想法如何在authlogic中沒有密碼的用戶登錄?

謝謝。

回答

1

你可以做這樣的事情在你的User型號:

acts_as_authentic do |config| 
    external = Proc.new { |r| r.externally_authenticated? } 

    config.merge_validates_confirmation_of_password_field_options(:unless => external) 
    config.merge_validates_length_of_password_confirmation_field_options(:unless => external) 
    config.merge_validates_length_of_password_field_options(:unless => external) 
end 

externally_authenticated?只是對檢查什麼是提供用戶信息,如果它是omniauth供應商之一,返回true用戶的方法。

+0

你如何檢查用戶是否通過omniauth驗證或沒有?即你在用'externalternallyauthenticated?'時使用了什麼?' – x1a4

+0

它不適用於我在配置中聲明外部並將它作爲選項傳遞。我必須傳遞'external_authenticated?'本身作爲它的工作選項。該方法的實現是一個單線程'!authentications.empty?或password.blank?' – codinguser

相關問題