feat: soft-delete for teamer accounts
addresses #869dv9br3
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Teamer\Profile;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\DeleteAccountType;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Service\Teamer\AccountDeletionHandler;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class DeleteAccountController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly AccountDeletionHandler $accountDeletionHandler)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/teamer/profile/delete-account', name: 'app_teamer_profile_delete_account')]
|
||||
#[IsGranted('ROLE_TEAMER')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
$form = $this->createForm(DeleteAccountType::class, null, ['hx_post' => $request->getUri()]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->accountDeletionHandler->delete($user, AccountDeletionHandler::SOURCE_SELF);
|
||||
|
||||
$this->addFlash('success', 'Dein Account wurde gelöscht');
|
||||
|
||||
// the session stays authenticated until the next request, so the logout is
|
||||
// done here rather than left to the DeletedUserSubscriber
|
||||
return new HxRedirectResponse($this->generateUrl('app_security_logout'));
|
||||
}
|
||||
|
||||
return $this->render('teamer/profile/modal_delete_account.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user