enable account deletion
This commit is contained in:
parent
2b5446555b
commit
0bde09ad5c
@ -49,4 +49,21 @@ class DetailsController extends ApiController
|
||||
|
||||
return new UserResource($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user's account.
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
try {
|
||||
event(new \Vanguard\Events\User\Deleted($user));
|
||||
$user->delete();
|
||||
return $this->respondWithSuccess();
|
||||
} catch (\Exception $e) {
|
||||
return $this->errorInternal($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,14 +127,16 @@ class UsersController extends ApiController
|
||||
*/
|
||||
public function destroy(User $user)
|
||||
{
|
||||
if ($user->id == auth()->id()) {
|
||||
return $this->errorForbidden(__("You cannot delete yourself."));
|
||||
try {
|
||||
event(new Deleted($user));
|
||||
|
||||
$user->delete();
|
||||
|
||||
return $this->respondWithSuccess();
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
return $this->errorInternal($e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
return $this->errorInternal($e->getMessage());
|
||||
}
|
||||
|
||||
event(new Deleted($user));
|
||||
|
||||
$this->users->delete($user->id);
|
||||
|
||||
return $this->respondWithSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ Route::group(['middleware' => ['auth', 'registration']], function () {
|
||||
Route::group(['middleware' => ['auth', 'verified']], function () {
|
||||
Route::get('me', 'Profile\DetailsController@index');
|
||||
Route::patch('me/details', 'Profile\DetailsController@update');
|
||||
Route::delete('me', 'Profile\DetailsController@destroy');
|
||||
Route::patch('me/details/auth', 'Profile\AuthDetailsController@update');
|
||||
Route::post('me/avatar', 'Profile\AvatarController@update');
|
||||
Route::delete('me/avatar', 'Profile\AvatarController@destroy');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user