This commit is contained in:
root 2019-10-27 21:26:30 +08:00
parent af72bb1a9b
commit 7d4fd24a92
2 changed files with 21 additions and 0 deletions

View File

@ -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) {
}

View File

@ -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');