【问题标题】:Devise Soft Email Confirmation设计软电子邮件确认
【发布时间】:2011-08-22 21:42:06
【问题描述】:

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

可确认模块可以做到这一点吗?有没有办法仍然创建一个尚未使用可确认模块确认其电子邮件的活动资源(用户)?关于实施此功能的任何一般性建议?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 devise


    【解决方案1】:

    我相信您可以使用 confirm_within 来指定锁定约束。您可以在调用 devise_for 时启用此功能。

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

    另外,您可以通过勾选“已确认?您的用户模型的状态。您可以在控制器中执行此操作,或使用 CanCan 或其他方式。您网站上的某些任务可能不需要确认;当用户与其他人互动或可以使用您的网站发送某些通知/电子邮件等时,您可能更需要这个。

    【讨论】:

    【解决方案2】:

    为已接受的答案添加更多细节。是的,您可以使用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 进行设置

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-10
        • 2019-08-04
        • 2012-09-03
        • 1970-01-01
        • 1970-01-01
        • 2016-03-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多