How to automatically login a new user after registration with a custom user provider in Silex?

被刻印的时光 ゝ 提交于 2019-12-03 21:23:19

Founded a solution, more like a workaround, but it make the job :

Instead of using the security/token method, I now log the user by generating a request to the login_check controller in order to generate all necessary login event.

In my controller :

$subRequest = Request::create(
$app['url_generator']->generate('login_check'),
    'POST',
    array(
        '_username' => $partner->getEmail(),
        '_password' => $rawPassword,
        $request->cookies->all(),
        array(),
        $request->server->all()
    )
);
$app->handle($subRequest, HttpKernelInterface::MASTER_REQUEST, false);

Wich require "'require_previous_session' => false" in your firewall configuration :

'secured' => array(
        'pattern' => '^/',
        'anonymous' => false,
        'form' => array(
            'login_path' => '/login',
            'check_path' => '/login_check',
            'require_previous_session' => false
        ),
        'logout' => array('logout_path' => '/logout', 'invalidate_session' => true),
        'users' => $app->share(function () use ($app) {
            return new Partner\DAO\PartnerDAO($app['db']);
        })
    )

I'm not sure it's a good or a bad solution, but it's working.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!