2013-11-25 30 views
0

我正在使用魔法寶石並嘗試重新驗證用戶以在「我的帳戶」部分更改密碼。所以基本上在表單上有old_password,password和password_confirmation。所以基本上,用戶已經登錄,但我想進行額外的身份驗證檢查來重置用戶的密碼以獲得額外的安全級別。Re =使用魔法寶石驗證用戶

我的問題是:如何用巫術實現這一目標?我正在瀏覽他們的源代碼,並在我認爲是用戶對象的地方發現了「authenticate」方法,但我怎麼稱呼它(注意我對rails比較新,並且仍然與ruby語法有關)

這是我有:

if (@password_reset.valid? && current_user.authenticate(@password_reset.email, @password_reset.old_password)) 

而且用戶模型

class User < ActiveRecord::Base 
    authenticates_with_sorcery! 
... 

回答

0

吉茲的相關部分,我很驚訝沒有人回答了這個問題,它結束了很簡單它。事實證明,我所要做的就是調用類方法而不是使用實例如下所示。

User.authenticate(@password_reset.email, @password_reset.old_password, false)