最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Devise send_reset_password_instructions invalid token in Active Admin Rails - Stack Overflow

programmeradmin1浏览0评论

I have this problem in ActiveAdmin. When I try to reset a user's password with devise send_reset_password_instructions.

member_action :reset_password, method: :get do
    resource.send_reset_password_instructions
    redirect_to users_path, notice: "instructions sent"
end 

I receive the email but when I try to set the new password I get the error reset password token is invalid. When I do the same process but within my webapp, the token is valid and the new password is set.

Any ideas/suggestions?

I have this problem in ActiveAdmin. When I try to reset a user's password with devise send_reset_password_instructions.

member_action :reset_password, method: :get do
    resource.send_reset_password_instructions
    redirect_to users_path, notice: "instructions sent"
end 

I receive the email but when I try to set the new password I get the error reset password token is invalid. When I do the same process but within my webapp, the token is valid and the new password is set.

Any ideas/suggestions?

Share Improve this question edited Feb 5 at 22:11 dbugger 16.4k10 gold badges33 silver badges35 bronze badges asked Feb 5 at 17:51 Rodrigo Ladrón de GuevaraRodrigo Ladrón de Guevara 2182 silver badges9 bronze badges 2
  • Have you confirmed the token on the user record is the same as that in the email? – dbugger Commented Feb 5 at 22:13
  • @dbugger for example, after triggering the email, I can see in my database the reset_password_token is '960f2c60a9534ad38f86c36bd7612a5c0e379fb075f862f8f0a833f606c83b21' but the url generated by the email is 'myapp.lvh.me:3000/auth/users/password/…' . Its a shorter/different token . But same thing when it's from the 'forgot password?' view and in that case is works perfectly. – Rodrigo Ladrón de Guevara Commented Feb 6 at 11:55
Add a comment  | 

1 Answer 1

Reset to default 0

Thanks to cursor ai, I finally made it work. I had to make a custom mailer and encrypt the 'public' token using Devise token_generator and then pass that token to the url. Like this:

encrypted_token = Devise.token_generator.digest(record, :reset_password_token, token)
record.reset_password_token = encrypted_token
record.reset_password_sent_at = Time.now.utc
record.save(validate: false)

@url = edit_password_url(record, reset_password_token: @token,
                                 subdomain: my_subdomain)

Now it works through ActiveAdmin and the web itself. Hope it helps someone

发布评论

评论列表(0)

  1. 暂无评论