Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * The authenticate action.
- *
- * @return FOS\RestBundle\View\View A view
- */
- public function getAuthenticateAction()
- {
- $request = $this->container->get('request');
- $username = $request->query->get('username');
- $password = $request->query->get('password');
- $userManager = $this->container->get('fos_user.user_manager');
- $user = $userManager->loadUserByUsername($username);
- if (!$user) {
- throw new NotFoundHttpException(sprintf("No user with username %s exists.", $username));
- }
- $encoderFactory = $this->container->get('security.encoder_factory');
- $encoder = $encoderFactory->getEncoder($user);
- if ($user->getPassword() !== $encoder->encodePassword($password, $user->getSalt())) {
- throw new AuthenticationException("Unable to authenticate user credentials.");
- }
- $view = $this->container->get('fos_rest.view');
- $view->setParameters($user);
- return $view;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement