如何通过Devise身份验证令牌直接从Active Admin中的edit_page重置用户的密码? [英] How to reset user´s password by Devise authentication token directly from edit_page in Active Admin?

查看:69
本文介绍了如何通过Devise身份验证令牌直接从Active Admin中的edit_page重置用户的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望admin_user能够从Active Admin edit_page重置用户的密码,但是当前卡住了。

I would like the admin_user to be able to reset user´s password from Active Admin edit_page, but am currently stuck.

我的想法是制作一个action_item按钮并从设计身份验证gem的@ user.send_reset_password_instructions方法启动一个有效的用户对象。但是,action_item无法得到任何通知:消息,这就是我被卡住的地方。

My idea was to make an action_item button and launch @user.send_reset_password_instructions method from devise authentication gem for a users object which works. But, action_item cannot get any notice: message and that´s where I´m stuck.

您能帮我实现可以启动@user的action_item按钮吗? send_reset_password_instructions,重定向到相同的user_edit_page和Flash通知消息发送成功而未呈现任何其他视图?

Can you please help me implement the action_item button which could launch the @user.send_reset_password_instructions, redirect to the same user_edit_page and flash notice message sending successful without rendering any other view??

action_item :reset_password,only: :edit do
  link_to "Reset password",edit_timein_employee_path
end

controller do
   def reset_password
    super do |success,failure|
    employee.send_reset_password_instructions
  end
 end
end

非常感谢!

推荐答案

我会这样做:确保将其粘贴到 app / admin / admin_user.rb 文件。我不会直接添加控制器方法,而是会使用 member_action dsl指令添加逻辑。

I would do it this way: make sure to paste this in the app/admin/admin_user.rb file. I would not add controller methods directly but would use the member_action dsl directive to add logic. Good luck!

action_item :reset_password, :only => :edit do
 link_to 'Reset password',  do_password_reset_admin_admin_user_path(resource), :method => :post
end

member_action :do_password_reset, :method => :post do
  flash.notice = "A mail containing password reset instructions has been sent to: #{resource.email}"
  resource.send_reset_password_instructions
  redirect_to edit_admin_admin_user_path(resource) and return
end

这篇关于如何通过Devise身份验证令牌直接从Active Admin中的edit_page重置用户的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆