Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Annotations :
- use Symfony\Component\HttpFoundation\JsonResponse;
- use FOS\UserBundle\Event\GetResponseUserEvent;
- use FOS\UserBundle\FOSUserEvents;
- use FOS\UserBundle\Event\FormEvent;
- use Symfony\Component\Security\Core\Security;
- use Symfony\Component\Security\Core\SecurityContextInterface;
- use Symfony\Component\Security\Core\Exception\AuthenticationException;
- Action :
- public function loginAction(Request $request)
- {
- $manager = $this->get('fos_user.user_manager');
- $factory = $this->get('security.encoder_factory');
- $email = $request->request->get('email');
- $password = $request->request->get('password');
- $em = $this->getDoctrine()->getManager();
- $bool = false;
- $response = [
- 'status' => false
- ];
- $user = $manager->findUserByUsername($email);
- $encoder = $factory->getEncoder($user);
- $bool = ($encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) ? true : false;
- if($bool) {
- $response = [
- 'status' => true,
- 'session' => [
- 'id' => $user->getId(),
- 'firstName' => $user->getFirstName(),
- 'lastName' => $user->getLastName(),
- ],
- ];
- }
- return $response;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement