/** * Login a user using a username and password * @param Request $request * * @return JsonResponse */ public function login(Request $request) { $username = $request->request->get('username'); $password = $request->request->get('password'); $errors = []; if (!$username) { $errors[] = 'missingUsername'; } if (!$password) { $errors[] = 'missingPassword'; } if ($username && $password) { $authEntity = $this->authManager->findAuthenticationByUsername($username); if ($authEntity) { $user = $authEntity->getUser(); $passwordValid = $this->encoder->isPasswordValid($user, $password); if ($passwordValid) { $this->updateLegacyPassword($authEntity, $password); $jwt = $this->jwtManager->createJwtFromUser($user); return $this->createSuccessResponseFromJWT($jwt); } } $errors[] = 'badCredentials'; } return new JsonResponse(array('status' => 'error', 'errors' => $errors, 'jwt' => null), JsonResponse::HTTP_BAD_REQUEST); }