强制 Restful 身份验证以特定用户身份登录(管理功能)?
我正在使用 Restful 身份验证,并且希望能够以不同用户的身份登录我们的网站,以调查他们可能遇到的问题(“看看他们看到了什么”)。由于所有密码都已加密,我显然不能只使用他们的密码。
那么,如何强制会话以特定用户身份登录呢?
I'm using Restful Authentication and I'd like to be able to log in as different users on our site to investigate issues they may be having ("see what they see"). Since all passwords are encrypted I obviously can't just use their passwords.
So, how can I force a session to be logged in as a specific user?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的
sessions_controller
中添加操作impersonate
,如下所示:然后在您的路由中使用成员
impersonate
扩展会话资源代码>:最后,在您的管理视图中的某个位置向每个用户添加一个名为“Impersonate”的按钮。它必须看起来像这样(假设用户位于局部变量
user
中):使用这种方法,您还可以避免覆盖任何跟踪数据,例如上次登录的时间等。
PS 不要忘记要求管理员在会话控制器中进行
模拟
操作。In your
sessions_controller
add actionimpersonate
like this:Then in your routes extend session resource with the member
impersonate
:Finally, somewhere in your admin views add a button to each user called "Impersonate". It will have to look something like this (assuming that user is in local variable
user
):Using this approach you also avoid overriding any tracking data such as time of the last login, etc.
P.S. Don't forget to require admin for
impersonate
action in sessions controller.只需使用您想要成为的用户的 ID 覆盖
session[:user_id]
即可。一种简单的方法是让用户以管理员身份登录,然后为他们提供用户名下拉列表。当他们提交表单时,让控制器设置session[:user_id]
,然后重新加载current_user
。然后管理员将“成为”该用户。Simply override
session[:user_id]
with the id of the user you want to be. One easy way is to have the user log in as an admin and then give them a drop-down of usernames. When they submit the form, have the controller setsession[:user_id]
and then reloadcurrent_user
. The admin will then 'become' that user.