diff --git a/app/bootstrap.php.d/30-trans.php b/app/bootstrap.php.d/30-trans.php index 287a76f..92cf0c3 100644 --- a/app/bootstrap.php.d/30-trans.php +++ b/app/bootstrap.php.d/30-trans.php @@ -42,10 +42,10 @@ $app['routes'] = $app->share($app->extend('routes', function ($routes, $app) { */ $app->get('/', function (Request $request) use ($app) { $accept = AcceptHeader::fromString($request->headers->get('Accept-Language')); - $cookie = $request->cookies->get('locale'); + $cookieValue = $request->cookies->get('locale'); - if (!empty($cookie) && in_array($cookie, $app['locales'])) { - $foundLocale = $cookie; + if (!empty($cookieValue) && in_array($cookieValue, $app['locales'])) { + $foundLocale = $cookieValue; } else { $foundLocale = $app['translator']->getLocale(); @@ -64,6 +64,8 @@ $app->get('/', function (Request $request) use ($app) { }); $app->after(function(Request $request, Response $response) use ($app) { - $cookie = new Cookie('locale', $request->attributes->get('_locale'), strtotime('+1 month')); + $value = $request->cookies->get('locale'); + + $cookie = new Cookie('locale', $value, strtotime('+1 month')); $response->headers->setCookie($cookie); }); diff --git a/app/bootstrap.php.d/70-security.php b/app/bootstrap.php.d/70-security.php index 1ee530c..c751293 100644 --- a/app/bootstrap.php.d/70-security.php +++ b/app/bootstrap.php.d/70-security.php @@ -3,10 +3,11 @@ use Gist\Service\UserProvider; use Silex\Provider\SecurityServiceProvider; use Gist\Service\SaltGenerator; -use Silex\Provider\SessionServiceProvider; use Gist\Security\AuthenticationProvider; use Gist\Security\AuthenticationListener; use Gist\Security\AuthenticationEntryPoint; +use Gist\Security\LogoutSuccessHandler; +use Silex\Provider\SessionServiceProvider; use Symfony\Component\Security\Http\HttpUtils; $app['enable_registration'] = true; @@ -25,7 +26,6 @@ $app['user.provider'] = $app->share(function ($app) { $app->register(new SessionServiceProvider()); - $app['security.authentication_listener.factory.form'] = $app->protect(function ($name, $options) use ($app) { $app['security.authentication_provider.'.$name.'.form'] = $app->share(function ($app) { return new AuthenticationProvider($app['user.provider']); @@ -37,7 +37,7 @@ $app['security.authentication_listener.factory.form'] = $app->protect(function ( $app['security.authentication_provider.'.$name.'.form'] ); }); - + return [ 'security.authentication_provider.'.$name.'.form', 'security.authentication_listener.'.$name.'.form', @@ -45,7 +45,7 @@ $app['security.authentication_listener.factory.form'] = $app->protect(function ( 'pre_auth' ]; }); - + $app->register( new SecurityServiceProvider(), [ @@ -56,12 +56,11 @@ $app->register( 'form' => [ 'login_path' => '_login', 'check_path' => '/login_check', - 'always_use_default_target_path' => true, + 'always_use_default_target_path' => false, 'default_target_path' => '/', ], 'logout' => [ 'path' => '/logout', - 'target' => '/', ], 'users' => $app->share(function () use ($app) { return $app['user.provider']; @@ -73,3 +72,12 @@ $app->register( ] ] ); + +$app['security.authentication.logout_handler._proto'] = $app->protect(function ($name, $options) use ($app) { + return $app->share(function () use ($name, $options, $app) { + return new LogoutSuccessHandler( + $app['security.http_utils'], + isset($options['target_url']) ? $options['target_url'] : '/' + ); + }); +}); diff --git a/src/Gist/Controller/LoginController.php b/src/Gist/Controller/LoginController.php index 7a854bf..538a688 100644 --- a/src/Gist/Controller/LoginController.php +++ b/src/Gist/Controller/LoginController.php @@ -8,6 +8,7 @@ use Gist\Form\UserRegisterForm; use Gist\Form\UserLoginForm; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\SecurityContext; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * Class LoginController diff --git a/src/Gist/Controller/MyController.php b/src/Gist/Controller/MyController.php index 1a980dc..73a705e 100644 --- a/src/Gist/Controller/MyController.php +++ b/src/Gist/Controller/MyController.php @@ -12,8 +12,6 @@ class MyController extends Controller { public function myAction(Request $request) { - $app = $this->getApp(); - return $this->render('My/my.html.twig'); } } diff --git a/src/Gist/Resources/views/Login/login.html.twig b/src/Gist/Resources/views/Login/login.html.twig index a59cea0..260230f 100644 --- a/src/Gist/Resources/views/Login/login.html.twig +++ b/src/Gist/Resources/views/Login/login.html.twig @@ -34,6 +34,8 @@

+ + diff --git a/src/Gist/Resources/views/base.html.twig b/src/Gist/Resources/views/base.html.twig index 939cd0f..324986c 100644 --- a/src/Gist/Resources/views/base.html.twig +++ b/src/Gist/Resources/views/base.html.twig @@ -44,7 +44,7 @@
  • - + {{ 'app.menu.my.logout.title'|trans }}
  • diff --git a/src/Gist/Security/LogoutSuccessHandler.php b/src/Gist/Security/LogoutSuccessHandler.php new file mode 100644 index 0000000..537fd0c --- /dev/null +++ b/src/Gist/Security/LogoutSuccessHandler.php @@ -0,0 +1,22 @@ + + */ +class LogoutSuccessHandler implements LogoutSuccessHandlerInterface +{ + public function onLogoutSuccess(Request $request) + { + $targetUrl = $request->query->get('target_url') ? $request->query->get('target_url') : '/'; + + return new RedirectResponse($targetUrl); + } +} +