Hem*_*til 1 ruby-on-rails devise
我正在尝试为尚未确认其帐户的用户重新生成确认令牌。我想在几天后向用户重新发送确认电子邮件。我正在点击此链接为该用户重新生成新令牌,并生成它但仍然无法正常工作。
https://github.com/plataformatec/devise/issues/2615。
我正在本地控制台上执行这些步骤。
@user = User.find_by_email("abc@xyz.com")
token = Devise.token_generator.generate(@user.class, :confirmation_token)
then in token i am getting array such as
token = ["gfbgk4535843tbk","8545kjbng8hguhggre8gergerkgjebg8gergkerjgg9ergejgn"]
Run Code Online (Sandbox Code Playgroud)
然后我只是发送这样的电子邮件
Devise::Mailer.confirmation_instructinos(@user,token.last).deliver
Run Code Online (Sandbox Code Playgroud)
然后它会向该用户发送一封电子邮件,但是当用户点击确认帐户时,它会将用户带到该站点,但是当用户尝试登录时它不起作用。
您可以使用 Devise 内置方法重新发送确认电子邮件:
users = User.where('confirmation_token IS NOT NULL')
users.each do |user|
user.send_confirmation_instructions
end
Run Code Online (Sandbox Code Playgroud)
如果令牌期限到期,send_confirmation_instructions方法应该生成一个新令牌。我已经多次使用这种方法,它达到了预期的效果。
你也可以尝试resend_confirmation_instructions,
# Resend confirmation token.
# Regenerates the token if the period is expired.
def resend_confirmation_instructions
pending_any_confirmation do
send_confirmation_instructions
end
end
Run Code Online (Sandbox Code Playgroud)
该方法上方的注释清楚地表明令牌将被重新生成。我还没有尝试过这个。