Advertisement
Guest User

Untitled

a guest
Mar 15th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. public function autoLoginAction($userData)
  2.     {
  3.         $em = $this->getDoctrine()->getManager();
  4.         $user = $em->getRepository('HfAppBundle:User')->findOneBy(array('email' => $userData['email']));
  5.         $userCreated = 0;
  6.         if (empty($user)) {
  7.             $kernel = $this->get('kernel');
  8.             $app = new Application($kernel);
  9.             $userName = $userData['email'];
  10.             $email = $userData['email'];
  11.             $password = $userData['password'];
  12.             $input = new StringInput("fos:user:create $userName $email $password");
  13.             $output = new StreamOutput(fopen('php://temp', 'w'));
  14.             $result = $app->doRun($input, $output);
  15.             rewind($output->getStream());
  16.             $commandResponse = stream_get_contents($output->getStream());
  17.             if (!$result) {
  18.                 $user = $em->getRepository('HfAppBundle:User')->findOneBy(array('email' => $email));
  19.             } else {
  20.                 //Unable to create user.
  21.                 echo $commandResponse;
  22.                 //return 0
  23.             }
  24.         }
  25.         if (!empty($user)) {
  26.             $user = $em->getRepository('HfAppBundle:User')->findOneBy(array('id' => $id));
  27.             $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
  28.             $this->get('session')->set('_security_main', serialize($token));
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement