Created
October 21, 2012 16:35
-
-
Save simonjodet/3927516 to your computer and use it in GitHub Desktop.
Silex automatic post-registration user authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$app['security.firewalls'] = array( | |
'user_firewall' => array( | |
'pattern' => new \Application\UserRequestMatcher($app['request']), | |
'form' => array('login_path' => '/login', 'check_path' => '/authenticate'), | |
'logout' => array('logout_path' => '/logout'), | |
'users' => $app->share(function () use ($app) | |
{ | |
return new \Application\UserProvider($app); | |
}), | |
), | |
); | |
//... | |
$app->post( | |
'/register', | |
function (\Silex\Application $app) | |
{ | |
$form->bind($app['request']); | |
$data = $form->getData(); | |
$UserModel = new \Application\UserModel($app); | |
$UserModel->create($data); | |
$User = new \Symfony\Component\Security\Core\User\User($data['username'], $data['password'], array('ROLE_USER')); | |
$app['security']->setToken(new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken($User, $User->getPassword(), 'user_firewall', array('ROLE_USER'))); | |
return $app->redirect('/'); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a bunch for this.