|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Application\Bundle\UserBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
8
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
9
|
|
|
use FOS\UserBundle\Model\UserInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ProfileController. |
|
13
|
|
|
*/ |
|
14
|
|
|
class ProfileController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Show the user. |
|
18
|
|
|
* |
|
19
|
|
|
* @return RedirectResponse |
|
20
|
|
|
*/ |
|
21
|
|
|
public function showAction() |
|
22
|
|
|
{ |
|
23
|
|
|
$user = $this->container->get('security.token_storage')->getToken()->getUser(); |
|
24
|
|
|
if (!is_object($user) || !$user instanceof UserInterface) { |
|
25
|
|
|
throw new AccessDeniedException('This user does not have access to this section.'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
return new RedirectResponse($this->container->get('router')->generate('cabinet')); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Edit the user. |
|
33
|
|
|
* |
|
34
|
|
|
* @return RedirectResponse|Response |
|
35
|
|
|
*/ |
|
36
|
|
|
public function editAction() |
|
37
|
|
|
{ |
|
38
|
|
|
$user = $this->container->get('security.token_storage')->getToken()->getUser(); |
|
39
|
|
|
if (!is_object($user) || !$user instanceof UserInterface) { |
|
40
|
|
|
throw new AccessDeniedException('This user does not have access to this section.'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$form = $this->container->get('fos_user.profile.form'); |
|
44
|
|
|
$formHandler = $this->container->get('fos_user.profile.form.handler'); |
|
45
|
|
|
|
|
46
|
|
|
$process = $formHandler->process($user); |
|
47
|
|
|
if ($process) { |
|
48
|
|
|
$this->setFlash('fos_user_success', 'profile.flash.updated'); |
|
49
|
|
|
|
|
50
|
|
|
return new RedirectResponse($this->getRedirectionUrl($user)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $this->container->get('templating')->renderResponse( |
|
54
|
|
|
'FOSUserBundle:Profile:edit.html.'.$this->container->getParameter('fos_user.template.engine'), |
|
55
|
|
|
['profileForm' => $form->createView()] |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Generate the redirection url when editing is completed. |
|
61
|
|
|
* |
|
62
|
|
|
* @param \FOS\UserBundle\Model\UserInterface $user |
|
63
|
|
|
* |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function getRedirectionUrl(UserInterface $user) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
return $this->container->get('router')->generate('fos_user_profile_show'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param string $action |
|
73
|
|
|
* @param string $value |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function setFlash($action, $value) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->container->get('session')->getFlashBag()->set($action, $value); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.