Update User controller

This commit is contained in:
Bubka 2020-01-21 22:40:16 +01:00
parent c044dcd6c6
commit 7ded76c92e
2 changed files with 41 additions and 1 deletions

View File

@ -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),
]);
}
}

View File

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