设计软件电子邮件确认

设计软件电子邮件确认

问题描述:

我有一个使用Devise和可确认模块的rails 3应用程序。但是,防止新注册的用户访问该网站,直到他们确认他们的电子邮件导致保留问题。相反,我们希望即时授予用户的访问权限,但仍会向他们发送确认电子邮件。然后,我们将运行后台任务来锁定在固定时间段内未确认其电子邮件的用户。设计软件电子邮件确认

这可能与可确认的模块?是否还有一种方法可以创建尚未使用可确认模块确认其电子邮件的活动资源(用户)?任何关于实施这个的一般建议?

我相信你可以使用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

将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

嗯设置,我认为正确的标志将是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