简体   繁体   中英

Devise expire notification on email confirmation

I have included confirmation module in devise gem and it working fine but i need to alert the user with some flash message on after 2 days(based on the devise config) for unconfirmed emails on login.

config.allow_unconfirmed_access_for = 2.days

how to add a button to resend mail for confirmation.

You need to create a button which links to a controller action, and create a route for it like resend_email_path(user) . Inside the controller action you need to include:

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

For more information on this method see:

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

Once you get it working normally you could do it ajaxy with remote: true

To add the flash message , put this in in the controller action where your uncomfirmed user is:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM