2011-05-11 185 views
5

我有一個使用Devise和可確認模塊的rails 3應用程序。但是,防止新註冊的用戶訪問該網站,直到他們確認他們的電子郵件導致保留問題。相反,我們希望即時授予用戶的訪問權限,但仍會向他們發送確認電子郵件。然後,我們將運行後臺任務來鎖定在固定時間段內未確認其電子郵件的用戶。設計軟件電子郵件確認

這可能與可確認的模塊?是否還有一種方法可以創建尚未使用可確認模塊確認其電子郵件的活動資源(用戶)?任何關於實施這個的一般建議?

回答

4

我相信你可以使用confirm_within指定鎖定約束。您可以在調用devise_for時啓用此功能。

http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable

此外,您還可以選擇通過檢查證實爲限制某些行爲「只」來確認用戶?您的用戶模型的狀態。你可以在控制器中執行此操作,或使用CanCan或其他任何操作。您網站上的某些任務可能不需要確認;當用戶與其他人交互或可以使用您的網站發送某些通知/電子郵件等時,您可能需要更多此類信息。

+0

謝謝,這看起來像它的我後。 – ghempton 2011-05-11 00:30:46

+0

confirm_within已棄用,請使用:allow_unconfirmed_access_for https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0 – gayavat 2012-03-20 10:53:52

2

將litte更多詳細信息添加到接受的答案。是的,您可以使用confirm_within,但在撥打devise而不是devise_for時需要執行此操作。

class User 
    devise :database_authenticatable, :encryptable, :confirmable, :rememberable,  :timeoutable, :lockable, 
    :stretches => 15, :pepper => 'abcdef', :confirm_within => 5.days, 
    :remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days 
end 

上面的代碼來自模型測試色器件

您還可以設置在config/initializers/devise.rb文件,config.confirm_within = 10.days

0

嗯設置,我認爲正確的標誌將是allow_unconfirmed_access_for

config.allow_unconfirmed_access_for = 5.days 

confirm_within只是指定通過電子郵件發送的令牌有多長時間。

更多來自config/initializers/devise.rb

# ==> Configuration for :confirmable 
# A period that the user is allowed to access the website even without 
# confirming his account. For instance, if set to 2.days, the user will be 
# able to access the website for two days without confirming his account, 
# access will be blocked just in the third day. Default is 0.days, meaning 
# the user cannot access the website without confirming his account. 
# config.allow_unconfirmed_access_for = 2.days 

# A period that the user is allowed to confirm their account before their 
# token becomes invalid. For example, if set to 3.days, the user can confirm 
# their account within 3 days after the mail was sent, but on the fourth day 
# their account can't be confirmed with the token any more. 
# Default is nil, meaning there is no restriction on how long a user can take 
# before confirming their account. 
# config.confirm_within = 3.days