ChangePasswordAction.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Module\User\AdminControllers\Actions;
  3. use App\Module\User\Services\UserService;
  4. use Dcat\Admin\Grid\RowAction;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Validator;
  7. /**
  8. * 修改用户密码操作
  9. */
  10. class ChangePasswordAction extends RowAction
  11. {
  12. /**
  13. * 操作标题
  14. *
  15. * @var string
  16. */
  17. protected $title = '<i class="fa fa-key"></i> 重置密码';
  18. /**
  19. * 处理请求
  20. *
  21. * @param Request $request
  22. * @return \Dcat\Admin\Actions\Response
  23. */
  24. public function handle(Request $request)
  25. {
  26. // 获取当前行的用户ID
  27. $userId = $this->getKey();
  28. // 调用服务修改密码
  29. $result = UserService::resetPassword($userId, '123456');
  30. if ($result === true) {
  31. return $this->response()->success('密码修改成功')->refresh();
  32. }
  33. return $this->response()->error('密码修改失败: ' . $result);
  34. }
  35. /**
  36. * 确认信息
  37. *
  38. * @return array|string|void
  39. */
  40. public function confirm()
  41. {
  42. return ['确定要重置该用户的密码吗?', '此操作将重置用户的登录密码为 123456 '];
  43. }
  44. }