i authenticate user in direct way (fosuserbundle, symfony2.2). i'am trying trivial example, doesn't work:
... use fos\userbundle\controller\registrationcontroller regcontroller; ... class defaultcontroller extends controller{ ... public function indexaction(){ $route = 'first_set_profile'; $url = $this->container->get('router')->generate($route); $response = new redirectresponse($url); $usermanager = $this->get('fos_user.user_manager'); $usertologin = $usermanager->finduserbyemail('aa@bb.com'); new regcontroller(authenticateuser($usertologin, $response)); ... }
this script running, not authenticate user email aa@bb.com...
thanks
this how can authenticate demo user example programmatic:
use symfony\component\security\core\authentication\token\usernamepasswordtoken; public function demologinaction(request $request) { $usermanager = $this->get('fos_user.user_manager'); $user = $usermanager->finduserbyemail('demo@example.com'); if (!$user) { throw $this->createnotfoundexception('no demouser found!'); } $token = new usernamepasswordtoken($user, $user->getpassword(), 'main', $user->getroles()); $context = $this->get('security.context'); $context->settoken($token); $router = $this->get('router'); $url = $router->generate('dashboard_show'); return $this->redirect($url); }
the third parameter in usernamepasswordtoken
must firewall name.
Comments
Post a Comment