diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ConfigController.php | 133 |
1 files changed, 123 insertions, 10 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index be6feb7c..9257ab18 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use PragmaRX\Recovery\Recovery as BackupCodes; | ||
5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
6 | use Symfony\Component\HttpFoundation\JsonResponse; | 7 | use Symfony\Component\HttpFoundation\JsonResponse; |
7 | use Symfony\Component\HttpFoundation\RedirectResponse; | 8 | use Symfony\Component\HttpFoundation\RedirectResponse; |
@@ -46,7 +47,7 @@ class ConfigController extends Controller | |||
46 | $activeTheme = $this->get('liip_theme.active_theme'); | 47 | $activeTheme = $this->get('liip_theme.active_theme'); |
47 | $activeTheme->setName($config->getTheme()); | 48 | $activeTheme->setName($config->getTheme()); |
48 | 49 | ||
49 | $this->get('session')->getFlashBag()->add( | 50 | $this->addFlash( |
50 | 'notice', | 51 | 'notice', |
51 | 'flashes.config.notice.config_saved' | 52 | 'flashes.config.notice.config_saved' |
52 | ); | 53 | ); |
@@ -68,7 +69,7 @@ class ConfigController extends Controller | |||
68 | $userManager->updateUser($user, true); | 69 | $userManager->updateUser($user, true); |
69 | } | 70 | } |
70 | 71 | ||
71 | $this->get('session')->getFlashBag()->add('notice', $message); | 72 | $this->addFlash('notice', $message); |
72 | 73 | ||
73 | return $this->redirect($this->generateUrl('config') . '#set4'); | 74 | return $this->redirect($this->generateUrl('config') . '#set4'); |
74 | } | 75 | } |
@@ -83,7 +84,7 @@ class ConfigController extends Controller | |||
83 | if ($userForm->isSubmitted() && $userForm->isValid()) { | 84 | if ($userForm->isSubmitted() && $userForm->isValid()) { |
84 | $userManager->updateUser($user, true); | 85 | $userManager->updateUser($user, true); |
85 | 86 | ||
86 | $this->get('session')->getFlashBag()->add( | 87 | $this->addFlash( |
87 | 'notice', | 88 | 'notice', |
88 | 'flashes.config.notice.user_updated' | 89 | 'flashes.config.notice.user_updated' |
89 | ); | 90 | ); |
@@ -99,7 +100,7 @@ class ConfigController extends Controller | |||
99 | $em->persist($config); | 100 | $em->persist($config); |
100 | $em->flush(); | 101 | $em->flush(); |
101 | 102 | ||
102 | $this->get('session')->getFlashBag()->add( | 103 | $this->addFlash( |
103 | 'notice', | 104 | 'notice', |
104 | 'flashes.config.notice.rss_updated' | 105 | 'flashes.config.notice.rss_updated' |
105 | ); | 106 | ); |
@@ -131,7 +132,7 @@ class ConfigController extends Controller | |||
131 | $em->persist($taggingRule); | 132 | $em->persist($taggingRule); |
132 | $em->flush(); | 133 | $em->flush(); |
133 | 134 | ||
134 | $this->get('session')->getFlashBag()->add( | 135 | $this->addFlash( |
135 | 'notice', | 136 | 'notice', |
136 | 'flashes.config.notice.tagging_rules_updated' | 137 | 'flashes.config.notice.tagging_rules_updated' |
137 | ); | 138 | ); |
@@ -153,12 +154,124 @@ class ConfigController extends Controller | |||
153 | ], | 154 | ], |
154 | 'twofactor_auth' => $this->getParameter('twofactor_auth'), | 155 | 'twofactor_auth' => $this->getParameter('twofactor_auth'), |
155 | 'wallabag_url' => $this->getParameter('domain_name'), | 156 | 'wallabag_url' => $this->getParameter('domain_name'), |
156 | 'enabled_users' => $this->get('wallabag_user.user_repository') | 157 | 'enabled_users' => $this->get('wallabag_user.user_repository')->getSumEnabledUsers(), |
157 | ->getSumEnabledUsers(), | ||
158 | ]); | 158 | ]); |
159 | } | 159 | } |
160 | 160 | ||
161 | /** | 161 | /** |
162 | * Enable 2FA using email. | ||
163 | * | ||
164 | * @Route("/config/otp/email", name="config_otp_email") | ||
165 | */ | ||
166 | public function otpEmailAction() | ||
167 | { | ||
168 | if (!$this->getParameter('twofactor_auth')) { | ||
169 | return $this->createNotFoundException('two_factor not enabled'); | ||
170 | } | ||
171 | |||
172 | $user = $this->getUser(); | ||
173 | |||
174 | $user->setGoogleAuthenticatorSecret(null); | ||
175 | $user->setBackupCodes(null); | ||
176 | $user->setEmailTwoFactor(true); | ||
177 | |||
178 | $this->container->get('fos_user.user_manager')->updateUser($user, true); | ||
179 | |||
180 | $this->addFlash( | ||
181 | 'notice', | ||
182 | 'flashes.config.notice.otp_enabled' | ||
183 | ); | ||
184 | |||
185 | return $this->redirect($this->generateUrl('config') . '#set3'); | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * Enable 2FA using OTP app, user will need to confirm the generated code from the app. | ||
190 | * | ||
191 | * @Route("/config/otp/app", name="config_otp_app") | ||
192 | */ | ||
193 | public function otpAppAction() | ||
194 | { | ||
195 | if (!$this->getParameter('twofactor_auth')) { | ||
196 | return $this->createNotFoundException('two_factor not enabled'); | ||
197 | } | ||
198 | |||
199 | $user = $this->getUser(); | ||
200 | $secret = $this->get('scheb_two_factor.security.google_authenticator')->generateSecret(); | ||
201 | |||
202 | $user->setGoogleAuthenticatorSecret($secret); | ||
203 | $user->setEmailTwoFactor(false); | ||
204 | |||
205 | $backupCodes = (new BackupCodes())->toArray(); | ||
206 | $backupCodesHashed = array_map( | ||
207 | function ($backupCode) { | ||
208 | return password_hash($backupCode, PASSWORD_DEFAULT); | ||
209 | }, | ||
210 | $backupCodes | ||
211 | ); | ||
212 | |||
213 | $user->setBackupCodes($backupCodesHashed); | ||
214 | |||
215 | $this->container->get('fos_user.user_manager')->updateUser($user, true); | ||
216 | |||
217 | return $this->render('WallabagCoreBundle:Config:otp_app.html.twig', [ | ||
218 | 'backupCodes' => $backupCodes, | ||
219 | 'qr_code' => $this->get('scheb_two_factor.security.google_authenticator')->getQRContent($user), | ||
220 | ]); | ||
221 | } | ||
222 | |||
223 | /** | ||
224 | * Cancelling 2FA using OTP app. | ||
225 | * | ||
226 | * @Route("/config/otp/app/cancel", name="config_otp_app_cancel") | ||
227 | */ | ||
228 | public function otpAppCancelAction() | ||
229 | { | ||
230 | if (!$this->getParameter('twofactor_auth')) { | ||
231 | return $this->createNotFoundException('two_factor not enabled'); | ||
232 | } | ||
233 | |||
234 | $user = $this->getUser(); | ||
235 | $user->setGoogleAuthenticatorSecret(null); | ||
236 | $user->setBackupCodes(null); | ||
237 | |||
238 | $this->container->get('fos_user.user_manager')->updateUser($user, true); | ||
239 | |||
240 | return $this->redirect($this->generateUrl('config') . '#set3'); | ||
241 | } | ||
242 | |||
243 | /** | ||
244 | * Validate OTP code. | ||
245 | * | ||
246 | * @param Request $request | ||
247 | * | ||
248 | * @Route("/config/otp/app/check", name="config_otp_app_check") | ||
249 | */ | ||
250 | public function otpAppCheckAction(Request $request) | ||
251 | { | ||
252 | $isValid = $this->get('scheb_two_factor.security.google_authenticator')->checkCode( | ||
253 | $this->getUser(), | ||
254 | $request->get('_auth_code') | ||
255 | ); | ||
256 | |||
257 | if (true === $isValid) { | ||
258 | $this->addFlash( | ||
259 | 'notice', | ||
260 | 'flashes.config.notice.otp_enabled' | ||
261 | ); | ||
262 | |||
263 | return $this->redirect($this->generateUrl('config') . '#set3'); | ||
264 | } | ||
265 | |||
266 | $this->addFlash( | ||
267 | 'two_factor', | ||
268 | 'scheb_two_factor.code_invalid' | ||
269 | ); | ||
270 | |||
271 | return $this->redirect($this->generateUrl('config_otp_app')); | ||
272 | } | ||
273 | |||
274 | /** | ||
162 | * @param Request $request | 275 | * @param Request $request |
163 | * | 276 | * |
164 | * @Route("/generate-token", name="generate_token") | 277 | * @Route("/generate-token", name="generate_token") |
@@ -178,7 +291,7 @@ class ConfigController extends Controller | |||
178 | return new JsonResponse(['token' => $config->getRssToken()]); | 291 | return new JsonResponse(['token' => $config->getRssToken()]); |
179 | } | 292 | } |
180 | 293 | ||
181 | $this->get('session')->getFlashBag()->add( | 294 | $this->addFlash( |
182 | 'notice', | 295 | 'notice', |
183 | 'flashes.config.notice.rss_token_updated' | 296 | 'flashes.config.notice.rss_token_updated' |
184 | ); | 297 | ); |
@@ -203,7 +316,7 @@ class ConfigController extends Controller | |||
203 | $em->remove($rule); | 316 | $em->remove($rule); |
204 | $em->flush(); | 317 | $em->flush(); |
205 | 318 | ||
206 | $this->get('session')->getFlashBag()->add( | 319 | $this->addFlash( |
207 | 'notice', | 320 | 'notice', |
208 | 'flashes.config.notice.tagging_rules_deleted' | 321 | 'flashes.config.notice.tagging_rules_deleted' |
209 | ); | 322 | ); |
@@ -269,7 +382,7 @@ class ConfigController extends Controller | |||
269 | break; | 382 | break; |
270 | } | 383 | } |
271 | 384 | ||
272 | $this->get('session')->getFlashBag()->add( | 385 | $this->addFlash( |
273 | 'notice', | 386 | 'notice', |
274 | 'flashes.config.notice.' . $type . '_reset' | 387 | 'flashes.config.notice.' . $type . '_reset' |
275 | ); | 388 | ); |