5

我的应用程序正在使用 Devise,并正确发送确认电子邮件,并在用户单击确认链接后正确确认用户。我还想在用户确认后发送第二封电子邮件。

关于如何延迟确认或两步确认有很多建议,但没有关于我正在寻找的内容(我可以找到)。

Devise::Module::Confirmable 文档告诉我要使用的方法是确认!,但我不知道该怎么做。有任何想法吗?

4

1 回答 1

4

Rails 设计:after_confirmation

只需定义一个 after_save 回调来检查用户是否被确认,如果是,则发送电子邮件。

如果您想节省一些 CPU 周期,您可以使用以下内容覆盖 Devise ConfirmationsController:

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
于 2012-06-04T08:51:18.487 回答