|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller\Profile; |
|
4
|
|
|
|
|
5
|
|
|
use App\Event\User\UserDeleteAccountEvent; |
|
6
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; |
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
8
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
11
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; |
|
12
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
13
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class UserProfileDeleteController |
|
17
|
|
|
* @package App\Controller\Profile |
|
18
|
|
|
* @IsGranted("ROLE_USER") |
|
19
|
|
|
*/ |
|
20
|
|
|
class UserProfileDeleteController extends AbstractController |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var EventDispatcherInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
private $dispatcher; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct(EventDispatcherInterface $dispatcher) |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
$this->dispatcher = $dispatcher; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @Route("/profile/delete", name="admin.delete_profile") |
|
36
|
|
|
*/ |
|
37
|
|
|
public function deleteProfile(Request $request, TokenStorageInterface $tokenStorage) |
|
38
|
|
|
{ |
|
39
|
|
|
//TODO:; Csrf Protection |
|
40
|
|
|
$user = $this->getUser(); |
|
41
|
|
|
|
|
42
|
|
|
$event = new UserDeleteAccountEvent($user); |
|
|
|
|
|
|
43
|
|
|
$this->dispatcher->dispatch(UserDeleteAccountEvent::NAME, $event); |
|
44
|
|
|
|
|
45
|
|
|
$tokenStorage->setToken(null); |
|
46
|
|
|
$request->getSession()->invalidate(); |
|
47
|
|
|
|
|
48
|
|
|
return $this->redirectToRoute('home'); |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
} |