Rails Devise, how to skip the confirmation email but still generate a confirmation token?

丶灬走出姿态 提交于 2020-01-01 11:02:02

问题


I'm using

      user.skip_confirmation!

To skip the devise email confirmation when a new user is added by an existing user. The problem with the skip_confirmation is that it does not generate a confirmation token.

I want to manually send a confirmation email which means I need a confirmation token.

How can I skip the devise confirmation email yet still generate a confirmaton_token to allow me to manually send a custom confirmation email to added users?

Thanks


回答1:


See confirmable.rb. In particular, around line 253 - 256. I think that should help you out.

In short:

module Devise
  module Models
    module Confirmable
      module ClassMethods
        # Generate a token checking if one does not already exist in the database.
        def confirmation_token
          generate_token(:confirmation_token)
        end
      end
    end
  end
end



回答2:


@user = User.new(:email => 'email@example.com', :password => 'password') 
@user.skip_confirmation_notification!
@user.save 

Here skip_confirmation_notification! generate a confirmation token but does not send confirmation email.



来源:https://stackoverflow.com/questions/11706101/rails-devise-how-to-skip-the-confirmation-email-but-still-generate-a-confirmati

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