enable account deletion
This commit is contained in:
@@ -49,4 +49,21 @@ class DetailsController extends ApiController
|
|||||||
|
|
||||||
return new UserResource($user);
|
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)
|
public function destroy(User $user)
|
||||||
{
|
{
|
||||||
if ($user->id == auth()->id()) {
|
try {
|
||||||
return $this->errorForbidden(__("You cannot delete yourself."));
|
|
||||||
}
|
|
||||||
|
|
||||||
event(new Deleted($user));
|
event(new Deleted($user));
|
||||||
|
|
||||||
$this->users->delete($user->id);
|
$user->delete();
|
||||||
|
|
||||||
return $this->respondWithSuccess();
|
return $this->respondWithSuccess();
|
||||||
|
} catch (\Illuminate\Database\QueryException $e) {
|
||||||
|
return $this->errorInternal($e->getMessage());
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->errorInternal($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ Route::group(['middleware' => ['auth', 'registration']], function () {
|
|||||||
Route::group(['middleware' => ['auth', 'verified']], function () {
|
Route::group(['middleware' => ['auth', 'verified']], function () {
|
||||||
Route::get('me', 'Profile\DetailsController@index');
|
Route::get('me', 'Profile\DetailsController@index');
|
||||||
Route::patch('me/details', 'Profile\DetailsController@update');
|
Route::patch('me/details', 'Profile\DetailsController@update');
|
||||||
|
Route::delete('me', 'Profile\DetailsController@destroy');
|
||||||
Route::patch('me/details/auth', 'Profile\AuthDetailsController@update');
|
Route::patch('me/details/auth', 'Profile\AuthDetailsController@update');
|
||||||
Route::post('me/avatar', 'Profile\AvatarController@update');
|
Route::post('me/avatar', 'Profile\AvatarController@update');
|
||||||
Route::delete('me/avatar', 'Profile\AvatarController@destroy');
|
Route::delete('me/avatar', 'Profile\AvatarController@destroy');
|
||||||
|
|||||||
Reference in New Issue
Block a user