How to reset user´s password by Devise authentication token directly from edit_page in Active Admin?

半世苍凉 提交于 2019-12-13 03:45:58

问题


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

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.

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

Thanks a lot!!


回答1:


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


来源:https://stackoverflow.com/questions/54470272/how-to-reset-user%c2%b4s-password-by-devise-authentication-token-directly-from-edit-p

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!