From 3ee8257dfc5ed37c13ac1e369cc90b087f8a3345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Sat, 4 Dec 2021 11:26:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Account/ChangePasswordController.php | 36 +++++++++++++++++++ app/Endpoint/Api/routes.php | 3 ++ resources/lang/zh_CN.json | 1 + 3 files changed, 40 insertions(+) create mode 100644 app/Endpoint/Api/Http/Controllers/Account/ChangePasswordController.php diff --git a/app/Endpoint/Api/Http/Controllers/Account/ChangePasswordController.php b/app/Endpoint/Api/Http/Controllers/Account/ChangePasswordController.php new file mode 100644 index 00000000..48b1d219 --- /dev/null +++ b/app/Endpoint/Api/Http/Controllers/Account/ChangePasswordController.php @@ -0,0 +1,36 @@ +validate([ + 'old_password' => ['bail', 'required', 'string', 'min:6', 'max:32'], + 'new_password' => ['bail', 'required', 'string', 'min:6', 'max:32'], + ]); + + $user = $request->user(); + + if (! $user->verifyPassword($input['old_password'])) { + throw new BizException(__('Invalid old password')); + } + + $user->update([ + 'password' => $input['new_password'], + ]); + + return response()->noContent(); + } +} diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index 4c565e18..8b7f1f71 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -1,5 +1,6 @@