How to generate reset password token

前端 未结 4 845
一生所求
一生所求 2021-02-12 14:32

I am using devise gem for authentication.

In my application admin will create the users, so I want the user\'s reset password link when admin creates users.

This

4条回答
  •  名媛妹妹
    2021-02-12 15:12

    You can generate a token with:

    Devise.token_generator.generate(User, :reset_password_token)
    

    Though this is just a useless string by itself. You need to attach it to the user if you actually want to use it in a link to reset passwords:

    user.reset_password_token = hashed_token
    user.reset_password_sent_at = Time.now.utc
    

    Then send them an email with the link:

    edit_password_url(@user, reset_password_token: @token)
    

提交回复
热议问题