php - Redirect after login succes + Silex -
what i'd check when loggin in if have cookie. , when have want redirect them $cookie_data/dashboard
.
because when select language on server, cookie set. redirect them $language/dashboard
.
i have:
$app['security.authentication.success_handler.secured_area'] = $app->share(function() use ($app) { $request = $app['request']; $cookies = $request->cookies; if($cookies->has("language")) { return $app->redirect('/nl/dashboard'); } });
but gives me errors:
warning: array_map(): error occurred while invoking map callback in /applications/mamp/htdocs/pst/vendor/silex/silex/src/silex/provider/securityserviceprovider.php on line 264 fatal error: uncaught exception 'runtimeexception' message 'accessed request service outside of request scope. try moving call before handler or controller.' in /applications/mamp/htdocs/pst/vendor/silex/silex/src/silex/application.php:141 stack trace: #0 /applications/mamp/htdocs/pst/vendor/pimple/pimple/lib/pimple.php(83): silex\application->silex\{closure}(object(silex\application)) #1 /applications/mamp/htdocs/pst/app/bootstrap.php(67): pimple->offsetget('request') #2 /applications/mamp/htdocs/pst/vendor/pimple/pimple/lib/pimple.php(126): {closure}(object(silex\application)) #3 /applications/mamp/htdocs/pst/vendor/pimple/pimple/lib/pimple.php(83): pimple::{closure}(object(silex\application)) #4 /applications/mamp/htdocs/pst/vendor/silex/silex/src/silex/provider/securityserviceprovider.php(409): pimple->offsetget('security.authen...') #5 /applications/mamp/htdocs/pst/vendor/pimple/pimple/lib/pimple.php(126): silex\provider\securityserviceprovider->silex\provider\{closure}(object(silex\application)) #6 /a in /applications/mamp/htdocs/pst/vendor/silex/silex/src/silex/application.php on line 141
how can make work or what's best practice?
i not sure correct, believe have return object of instance, see this question details (particularly answer of igorw)
another option intercept authentication_success event of dispatcher, tried following:
$app['dispatcher']->addlistener(authenticationevents::authentication_success , function($authevent) use ($app) { $request = $app['request']; $cookiekeys = $request->cookies->keys(); $app['monolog']->addinfo('available cookies are: ' . implode(', ', $cookiekeys)); return $app->redirect('some_url_here'); });
in log see cookies, there aren't errors, redirect not work either! after inspecting logs (monolog) saw following routes called on when trying access secured area /admin
:
http://localhost:8888/silex-skeleton/web/index_dev.php/login
get (redirect login form)http://localhost:8888/silex-skeleton/web/index_dev.php/admin/login_check
post (authenticate)http://localhost:8888/silex-skeleton/web/index_dev.php/admin
get (redirect requested url)
the authentication events called on intermediate /login_check
request , returning different values not seem have impact on overall result, @ least did not manage this. i'm wondering why don't redirect in route handler function??? result same, @ least if understood question correctly. example put code in handler secured area, like:
$app->get('/dashboard', function() use ($app) { $request = $app['request']; $cookies = $request->cookies; if($cookies->has("language")) { return $app->redirect('/nl/dashboard'); } return new response(.....) });
Comments
Post a Comment