简体   繁体   English

使用devise gem更改其他用户的密码

[英]Change password of other user in using devise gem

I have used devise gem for authentication. 我已使用devise gem进行身份验证。 There are multiple users and i am admin. 有多个用户,我是管理员。 I want to change the password of other users. 我想更改其他用户的密码。 Is it possible to do so? 有可能这样做吗?

I can't think of a better way but you can implement an action which passes the new password typed in a form field and do the following. 我想不出更好的方法,但是您可以实现一个操作,该操作传递在表单字段中键入的新密码,然后执行以下操作。 The code below will work in the rails console as well.(tested on Device 4.2.0) 以下代码也将在rails控制台中工作。(在Device 4.2.0上测试)

u = User.find(user_id)
u.password = "changed_password"
u.save

EDIT: I would strongly suggest to rethink doing this . 编辑: 我强烈建议重新考虑这样做 How would the existing user know what his password is. 现有用户将如何知道他的密码是什么。 Alternative - you may also build a mechanism so that users can use the forgot password method and set their password themselves. 替代方法-您还可以建立一种机制,使用户可以使用忘记密码的方法并自行设置密码。 To do so you can make the encrypted_password null and send them a forgot password email(with appropriate message in the mail that their current password has expired and they need to set a new one) so that they can use it to set their password themselves. 为此,您可以将encrypted_pa​​ssword设置为null,然后向他们发送忘记密码的电子邮件(邮件中包含相应的消息,告知他们当前的密码已过期,需要设置一个新密码),以便他们可以自己设置密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM