我正在使用设计:在我的用户模型中确认。
我的要求是,在注册/注册后,用户应该成功登录(无需确认),并且确认链接也会发送到用户的电子邮箱。
如果用户未确认其帐户,则第二次不应该登录。
如何实现这一目标?
由于
答案 0 :(得分:6)
要实现完全您正在寻找的内容,您需要创建一些魔术来覆盖Devise confirmations controller以及sessions controller。如果您选择沿着这条路走下去,那么在Wiki页面上有许多覆盖Devise控制器的例子。通过启用:trackable
模块,您将可以访问sign_in_count
,您可以使用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
initializer文件,从第122行开始,您会看到您可以在一段时间内允许未经证实访问您的应用程序。
send_instructions
我认为最终,从开发人员和最终用户的角度来看,启用此功能并将其设置为适合您的应用程序的功能将是更好的方法。我还要确保在第34行的locale中放置一些内容,{{1}}通知用户他们有x个小时/天的时间来使用该视频,然后他们必须通过电子邮件确认其帐户。
答案 1 :(得分:3)
最简单的是你指出config.allow_unconfirmed_access_for = 2.minutes
,以便在注册后立即登录,但两分钟后,除非他在两分钟内退出,否则他将无法登录。