Advertisement
Guest User

Untitled

a guest
May 29th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. Annotations :
  2.  
  3.  
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use FOS\UserBundle\Event\GetResponseUserEvent;
  6. use FOS\UserBundle\FOSUserEvents;
  7. use FOS\UserBundle\Event\FormEvent;
  8. use Symfony\Component\Security\Core\Security;
  9. use Symfony\Component\Security\Core\SecurityContextInterface;
  10. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  11.  
  12.  
  13. Action :
  14.  
  15. public function loginAction(Request $request)
  16. {
  17. $manager = $this->get('fos_user.user_manager');
  18. $factory = $this->get('security.encoder_factory');
  19.  
  20. $email = $request->request->get('email');
  21. $password = $request->request->get('password');
  22.  
  23. $em = $this->getDoctrine()->getManager();
  24.  
  25. $bool = false;
  26.  
  27. $response = [
  28. 'status' => false
  29. ];
  30.  
  31. $user = $manager->findUserByUsername($email);
  32. $encoder = $factory->getEncoder($user);
  33. $bool = ($encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) ? true : false;
  34.  
  35. if($bool) {
  36. $response = [
  37. 'status' => true,
  38. 'session' => [
  39. 'id' => $user->getId(),
  40. 'firstName' => $user->getFirstName(),
  41. 'lastName' => $user->getLastName(),
  42. ],
  43. ];
  44. }
  45.  
  46. return $response;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement