【问题标题】:Devise expire notification on email confirmation设计电子邮件确认过期通知
【发布时间】:2016-03-03 13:10:44
【问题描述】:

我在设计 gem 中包含了确认模块,它工作正常,但我需要在 2 天后(基于设计配置)提醒用户登录时未确认的电子邮件。

config.allow_unconfirmed_access_for = 2.days

如何添加一个按钮来重新发送邮件以进行确认。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 devise devise-confirmable


    【解决方案1】:

    您需要创建一个链接到控制器操作的按钮,并为其创建一个路由,例如resend_email_path(user)。在控制器动作中,您需要包括:

      def resend_email
        user = User.find(params[:id])
        user.send_confirmation_instructions
      end
    

    有关此方法的更多信息,请参阅:

    https://github.com/plataformatec/devise/blob/9f37b6eff7b4f9b0441be5a687b3091db82befc4/lib/devise/models/confirmable.rb#L110-L117

    一旦你让它正常工作,你可以用 remote: true ajaxy 来做它

    要添加 flash 消息,请将其放入未确认用户所在的控制器操作中:

    if current_user.confirmation_period_expired?
      flash[:error] = "Confirmation Time Expired. #{link_to 'Resend email', resend_email_path(user)}".html_safe
    end
    

    见:https://github.com/plataformatec/devise/blob/9f37b6eff7b4f9b0441be5a687b3091db82befc4/lib/devise/models/confirmable.rb#L218-L220

    【讨论】:

    • 感谢 Abram,但如何在到期日添加闪光警报
    猜你喜欢
    • 1970-01-01
    • 2011-04-20
    • 2011-08-22
    • 1970-01-01
    • 2012-03-10
    • 2019-08-04
    • 2023-03-20
    • 2012-09-03
    • 1970-01-01
    相关资源
    最近更新 更多