diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 3450d0db..f8be0351 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -85,7 +85,7 @@ public function register(Request $request) $this->validate($request, [ 'name' => 'required', 'email' => 'required|email', - 'password' => 'required|confirmed', + 'password' => 'required|confirmed|min:8', ]); $input = $request->all(); @@ -107,4 +107,41 @@ public function getDetails() { return response()->json(Auth::user(), 200); } + + + /** + * Update the user's profile information. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function update(Request $request) + { + $user = $request->user(); + + $this->validate($request, [ + 'name' => 'required', + 'email' => 'required|email|unique:users,email,'.$user->id, + ]); + + return tap($user)->update($request->only('name', 'email')); + } + + + /** + * Update the user's password. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function changePassword(Request $request) + { + $this->validate($request, [ + 'password' => 'required|confirmed|min:8', + ]); + + $request->user()->update([ + 'password' => bcrypt($request->password), + ]); + } } \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index 03bd3c63..8cc06e03 100644 --- a/routes/api.php +++ b/routes/api.php @@ -27,7 +27,10 @@ Route::group(['middleware' => 'auth:api'], function() { Route::post('logout', 'UserController@logout'); + Route::patch('user/edit', 'UserController@update'); + Route::patch('user/password', 'UserController@changePassword'); Route::get('user', 'UserController@getDetails'); + Route::apiResource('twofaccounts', 'TwoFAccountController'); Route::get('twofaccounts/{twofaccount}/totp', 'TwoFAccountController@generateTOTP')->name('twofaccounts.generateTOTP'); Route::post('qrcode/decode', 'QrCodeController@decode');