From 7d4fd24a92df7e6965d05a52f0517d76aae659e7 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 27 Oct 2019 21:26:30 +0800 Subject: [PATCH] update --- app/Http/Controllers/UserController.php | 20 ++++++++++++++++++++ routes/api.php | 1 + 2 files changed, 21 insertions(+) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index bf79b93b..55a953aa 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -18,6 +18,26 @@ class UserController extends Controller ]); } + public function changePassword (Request $request) { + if (empty($request->input('old_password'))) { + abort(500, '旧密码不能为空'); + } + if (empty($request->input('new_password'))) { + abort(500, '新密码不能为空'); + } + $user = User::find($request->session()->get('id')); + if (!password_verify($request->input('old_password'), $user->password)) { + abort(500, '旧密码有误'); + } + $user->password = password_hash($request->input('new_password'), PASSWORD_DEFAULT); + if (!$user->save()) { + abort(500, '保存失败'); + } + return response([ + 'data' => true + ]); + } + public function index (Request $request) { } diff --git a/routes/api.php b/routes/api.php index e4d203a8..a5d13d22 100755 --- a/routes/api.php +++ b/routes/api.php @@ -51,6 +51,7 @@ Route::prefix('v1') Route::get('subscribe', 'UserController@subscribe'); Route::get('logout', 'UserController@logout'); Route::get('info', 'UserController@info'); + Route::post('changePassword', 'UserController@changePassword'); // Order Route::get('order', 'OrderController@index'); Route::post('order/save', 'OrderController@save');