How to generate reset password token

前端 未结 4 712
一生所求
一生所求 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:10

    If you are using devise why are you creating your own password reset token? Devise has a feature for that. http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable

    In case you wonder this is what devise does when the user wants to reset his password:

      raw, enc = Devise.token_generator.generate(self.class, :reset_password_token)
    
      self.reset_password_token   = enc
      self.reset_password_sent_at = Time.now.utc
      self.save(validate: false)
    

    self is an User object here

    In your URL you then have to pass raw as reset_password_token parameter

提交回复
热议问题