Rails: Devise: Sending an email after user comfirms registration

北城以北 提交于 2019-12-06 04:56:37

问题


My application is using Devise, and is sending out confirmation emails properly, and confirming users properly as well after they click on the confirmation link. I would also like to send a second email AFTER the user is confirmed.

There is a lot of advice on how to delay confirmation, or 2-step confirmation, but nothing on what I'm looking for (that I can find).

The Devise::Module::Confirmable documentation tells me that the method to use is confirm!, but I am not sure how to do this. Any ideas?


回答1:


Rails Devise: after_confirmation

Simply define an after_save callback that checks to see if a user was confirmed, and if so, sends the email.

If you want to save a few CPU cycles, you could override the Devise ConfirmationsController with something like this:

class ConfirmationsController < Devise::ConfirmationsController

    def show
        self.resource = resource_class.confirm_by_token(params[:confirmation_token])

        if resource.errors.empty?
            set_flash_message(:notice, :confirmed) if is_navigational_format?
            sign_in(resource_name, resource)

            # Send the user a second email          
            send_post_confirmation_email

            respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
        else
            respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
        end
    end
end


来源:https://stackoverflow.com/questions/10877475/rails-devise-sending-an-email-after-user-comfirms-registration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!