2015-02-24 67 views
0

所以我想重寫Devise :: RegistrationsController,他們確實有wiki和噸的教程。我無法找到的一件事是如何在執行需求管理員審批功能的同時覆蓋控制器的最佳實施。覆蓋設計:: RegistratoinsController

我想我得到了它的竅門,但之前我去任何進一步(從對設計的源代碼全部看完),我想知道,在註冊控制器上有,做一個行:

resource.active_for_authentication? 

然而,會話控制器,它只是這個:

def create 
self.resource = warden.authenticate!(auth_options) 
set_flash_message(:notice, :signed_in) if is_flashing_format? 
sign_in(resource_name, resource) 
yield resource if block_given? 
respond_with resource, location: after_sign_in_path_for(resource) 
end 

我想知道的是,如果它沒有確認或active_for_authentication返回false,哪裏或如何做的會話控制器檢查呢?我試圖追溯源代碼,但沒有運氣。

因此,任何對Devise非常熟悉的人,或許您可以回答我的問題?謝謝。

回答

1

驗證用戶並在每個請求中,Devise通過調用model.active_for_authentication?來檢查您的模型是否處於活動狀態。該方法被其他設計模塊覆蓋。例如:可確認覆蓋.active_for_authentication?只有在您的模型得到確認後纔會返回true。

您可以改寫自己這個方法,但如果你做什麼,不要忘記調用超:

def active_for_authentication? 
    super && special_condition_is_valid? 
end 

每當active_for_authentication?返回false,Devise使用inactive_message方法詢問你的模型爲什麼不活動的原因。您也可以覆蓋它:

def inactive_message 
    special_condition_is_valid? ? super : :special_condition_is_not_valid 
end