aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php9
-rw-r--r--src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php8
-rw-r--r--src/Wallabag/UserBundle/Resources/views/layout.html.twig4
3 files changed, 13 insertions, 8 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 99576fbb..be6feb7c 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
8use Symfony\Component\HttpFoundation\Request; 8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; 9use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
10use Symfony\Component\Routing\Annotation\Route; 10use Symfony\Component\Routing\Annotation\Route;
11use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint;
11use Wallabag\CoreBundle\Entity\Config; 12use Wallabag\CoreBundle\Entity\Config;
12use Wallabag\CoreBundle\Entity\TaggingRule; 13use Wallabag\CoreBundle\Entity\TaggingRule;
13use Wallabag\CoreBundle\Form\Type\ChangePasswordType; 14use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
@@ -341,11 +342,13 @@ class ConfigController extends Controller
341 */ 342 */
342 public function setLocaleAction(Request $request, $language = null) 343 public function setLocaleAction(Request $request, $language = null)
343 { 344 {
344 if (null !== $language) { 345 $errors = $this->get('validator')->validate($language, (new LocaleConstraint()));
345 $this->get('session')->set('_locale', $language); 346
347 if (0 === \count($errors)) {
348 $request->getSession()->set('_locale', $language);
346 } 349 }
347 350
348 return $this->redirect($request->headers->get('referer')); 351 return $this->redirect($request->headers->get('referer', $this->generateUrl('homepage')));
349 } 352 }
350 353
351 /** 354 /**
diff --git a/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php b/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php
index 367cdfb0..dc1db5c7 100644
--- a/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php
+++ b/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php
@@ -6,8 +6,10 @@ use Symfony\Component\HttpFoundation\Session\Session;
6use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 6use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
7 7
8/** 8/**
9 * Stores the locale of the user in the session after the 9 * Stores the locale of the user in the session after the login.
10 * login. This can be used by the LocaleListener afterwards. 10 * If no locale are defined (if user doesn't change it from the login screen), override it with the user's config one.
11 *
12 * This can be used by the LocaleListener afterwards.
11 * 13 *
12 * @see http://symfony.com/doc/master/cookbook/session/locale_sticky_session.html 14 * @see http://symfony.com/doc/master/cookbook/session/locale_sticky_session.html
13 */ 15 */
@@ -30,7 +32,7 @@ class UserLocaleListener
30 { 32 {
31 $user = $event->getAuthenticationToken()->getUser(); 33 $user = $event->getAuthenticationToken()->getUser();
32 34
33 if (null !== $user->getConfig()->getLanguage()) { 35 if (null !== $user->getConfig()->getLanguage() && null === $this->session->get('_locale')) {
34 $this->session->set('_locale', $user->getConfig()->getLanguage()); 36 $this->session->set('_locale', $user->getConfig()->getLanguage());
35 } 37 }
36 } 38 }
diff --git a/src/Wallabag/UserBundle/Resources/views/layout.html.twig b/src/Wallabag/UserBundle/Resources/views/layout.html.twig
index 6934c686..b53f8746 100644
--- a/src/Wallabag/UserBundle/Resources/views/layout.html.twig
+++ b/src/Wallabag/UserBundle/Resources/views/layout.html.twig
@@ -16,8 +16,8 @@
16 {% endblock fos_user_content %} 16 {% endblock fos_user_content %}
17 </div> 17 </div>
18 <div class="center"> 18 <div class="center">
19 <a href="{{ path('changeLocale', {'language': 'de'}) }}">Deutsch</a> 19 <a href="{{ path('changeLocale', {'language': 'de'}) }}">Deutsch</a>
20 <a href="{{ path('changeLocale', {'language': 'en'}) }}">English</a> 20 <a href="{{ path('changeLocale', {'language': 'en'}) }}">English</a>
21 <a href="{{ path('changeLocale', {'language': 'fr'}) }}">Français</a> 21 <a href="{{ path('changeLocale', {'language': 'fr'}) }}">Français</a>
22 </div> 22 </div>
23 </div> 23 </div>