2012-07-10 87 views
2

我使用的設計:在我的用戶模型中可以確認。如何在沒有確認註冊後確認鏈接

我的要求是,在註冊/註冊後,用戶應該成功登錄(沒有確認)並且確認鏈接也發送到用戶的郵箱。

第二次如果用戶沒有確認他的帳戶,則不應登錄。

如何實現這一目標?

感謝

回答

5

爲了實現正是你在找什麼,你將需要重寫設計confirmations controller還有sessions controller創造一些魔法。如果您選擇沿着這條路走下去,在Wiki頁面上有很多覆蓋Devise控制器的例子。通過啓用:trackable模塊,您將有權訪問sign_in_count,您可以使用它來檢查並只允許一個,直到它們被確認。

但是,我想提供一個更容易的解決方案,您可能會接受。如果您查看devise.rbinitializer文件(從第122行開始),您會看到您可以在一段時間內允許未經證實的訪問您的應用程序。

# ==> 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 

我認爲到最後,啓用該功能,並將其設置爲某事爲您的應用將是更好的做法可以接受,無論從開發者和最終用戶的角度來看。我也一定會在send_instructionssend_instructions上寫下locale的內容,通知用戶他們有x個小時/天的時間來使用視線,然後他們必須通過電子郵件確認他們的賬戶。

+0

太棒了。謝謝+1 – ajbraus 2014-04-12 03:07:25

+0

任何訣竅讓這個工作?我取消了該行的註釋,但在嘗試通過API登錄時似乎沒有工作。 – 2014-10-15 03:59:11

3

最簡單的方法就是您註明config.allow_unconfirmed_access_for = 2.minutes,這樣在註冊後他將立即登錄,但兩分鐘後,除非他在兩分鐘內註銷並登錄,否則他將無法登錄。