diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ConfigController.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index d4170d39..23af98e5 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -10,12 +10,16 @@ use Symfony\Component\HttpFoundation\Request; | |||
10 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | 10 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
11 | use Wallabag\CoreBundle\Entity\Config; | 11 | use Wallabag\CoreBundle\Entity\Config; |
12 | use Wallabag\CoreBundle\Entity\TaggingRule; | 12 | use Wallabag\CoreBundle\Entity\TaggingRule; |
13 | use Wallabag\CoreBundle\Event\Activity\Actions\User\UserDeletedEvent; | ||
14 | use Wallabag\CoreBundle\Event\Activity\Actions\User\UserEditedEvent; | ||
13 | use Wallabag\CoreBundle\Form\Type\ConfigType; | 15 | use Wallabag\CoreBundle\Form\Type\ConfigType; |
14 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; | 16 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; |
15 | use Wallabag\CoreBundle\Form\Type\RssType; | 17 | use Wallabag\CoreBundle\Form\Type\RssType; |
16 | use Wallabag\CoreBundle\Form\Type\TaggingRuleType; | 18 | use Wallabag\CoreBundle\Form\Type\TaggingRuleType; |
17 | use Wallabag\CoreBundle\Form\Type\UserInformationType; | 19 | use Wallabag\CoreBundle\Form\Type\UserInformationType; |
18 | use Wallabag\CoreBundle\Tools\Utils; | 20 | use Wallabag\CoreBundle\Tools\Utils; |
21 | use Wallabag\FederationBundle\Form\Type\AccountType; | ||
22 | use Wallabag\UserBundle\Entity\User; | ||
19 | 23 | ||
20 | class ConfigController extends Controller | 24 | class ConfigController extends Controller |
21 | { | 25 | { |
@@ -82,6 +86,50 @@ class ConfigController extends Controller | |||
82 | if ($userForm->isSubmitted() && $userForm->isValid()) { | 86 | if ($userForm->isSubmitted() && $userForm->isValid()) { |
83 | $userManager->updateUser($user, true); | 87 | $userManager->updateUser($user, true); |
84 | 88 | ||
89 | $this->get('event_dispatcher')->dispatch(UserEditedEvent::NAME, new UserEditedEvent($user->getAccount())); | ||
90 | |||
91 | $this->get('session')->getFlashBag()->add( | ||
92 | 'notice', | ||
93 | 'flashes.config.notice.user_updated' | ||
94 | ); | ||
95 | |||
96 | return $this->redirect($this->generateUrl('config').'#set3'); | ||
97 | } | ||
98 | |||
99 | // handle account information | ||
100 | $account = $user->getAccount(); | ||
101 | $accountForm = $this->createForm(AccountType::class, $account, [ | ||
102 | 'action' => $this->generateUrl('config').'#set3', | ||
103 | ]); | ||
104 | $accountForm->handleRequest($request); | ||
105 | |||
106 | if ($accountForm->isSubmitted() && $accountForm->isValid()) { | ||
107 | |||
108 | $avatar = $account->getAvatar(); | ||
109 | $banner = $account->getBanner(); | ||
110 | |||
111 | if (null !== $avatar) { | ||
112 | $avatarFileName = md5(uniqid('', true)) . '.' . $avatar->guessExtension(); | ||
113 | |||
114 | $avatar->move( | ||
115 | $this->getParameter('media_directory') . '/avatar', | ||
116 | $avatarFileName | ||
117 | ); | ||
118 | $account->setAvatar($avatarFileName); | ||
119 | } | ||
120 | |||
121 | if (null != $banner) { | ||
122 | $bannerFileName = md5(uniqid('', true)) . '.' . $banner->guessExtension(); | ||
123 | |||
124 | $banner->move( | ||
125 | $this->get('media_directory') . '/banner', | ||
126 | $bannerFileName | ||
127 | ); | ||
128 | $account->setBanner($bannerFileName); | ||
129 | } | ||
130 | |||
131 | $this->get('event_dispatcher')->dispatch(UserEditedEvent::NAME, new UserEditedEvent($user)); | ||
132 | |||
85 | $this->get('session')->getFlashBag()->add( | 133 | $this->get('session')->getFlashBag()->add( |
86 | 'notice', | 134 | 'notice', |
87 | 'flashes.config.notice.user_updated' | 135 | 'flashes.config.notice.user_updated' |
@@ -145,6 +193,7 @@ class ConfigController extends Controller | |||
145 | 'pwd' => $pwdForm->createView(), | 193 | 'pwd' => $pwdForm->createView(), |
146 | 'user' => $userForm->createView(), | 194 | 'user' => $userForm->createView(), |
147 | 'new_tagging_rule' => $newTaggingRule->createView(), | 195 | 'new_tagging_rule' => $newTaggingRule->createView(), |
196 | 'account' => $accountForm->createView(), | ||
148 | ], | 197 | ], |
149 | 'rss' => [ | 198 | 'rss' => [ |
150 | 'username' => $user->getUsername(), | 199 | 'username' => $user->getUsername(), |
@@ -400,9 +449,13 @@ class ConfigController extends Controller | |||
400 | $this->get('security.token_storage')->setToken(null); | 449 | $this->get('security.token_storage')->setToken(null); |
401 | $request->getSession()->invalidate(); | 450 | $request->getSession()->invalidate(); |
402 | 451 | ||
452 | $account = $user->getAccount(); | ||
453 | |||
403 | $em = $this->get('fos_user.user_manager'); | 454 | $em = $this->get('fos_user.user_manager'); |
404 | $em->deleteUser($user); | 455 | $em->deleteUser($user); |
405 | 456 | ||
457 | $this->get('event_dispatcher')->dispatch(UserDeletedEvent::NAME, new UserDeletedEvent($account)); | ||
458 | |||
406 | return $this->redirect($this->generateUrl('fos_user_security_login')); | 459 | return $this->redirect($this->generateUrl('fos_user_security_login')); |
407 | } | 460 | } |
408 | 461 | ||