示例#1
0
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         if ($this->env != 'dev') {
             $msg = $this->translator->trans($exception->getMessageKey(), $exception->getMessageData(), 'security');
         } else {
             $msg = $exception->getMessage();
         }
         return new JsonResponse($msg, Response::HTTP_UNAUTHORIZED);
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $data = array('message' => strtr($exception->getMessageKey(), $exception->getMessageData()));
     return new JsonResponse($data, 403);
 }
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     throw new \Exception();
     return new Response(strtr($exception->getMessageKey(), $exception->getMessageData()), 403);
 }
 public function getMessageData()
 {
     return $this->messageData !== null ? $this->messageData : parent::getMessageData();
 }
示例#5
0
 /**
  * Gets the message from the specific AuthenticationException and then
  * translates it. The translation process allows us to customize the
  * messages we want - see the translations/en.yml file.
  */
 private function getMessage(AuthenticationException $authException = null)
 {
     $key = $authException ? $authException->getMessageKey() : 'authentication_required';
     $parameters = $authException ? $authException->getMessageData() : array();
     return $this->translator->trans($key, $parameters);
 }
 /**
  * This is called when an interactive authentication attempt fails. This is
  * called by authentication listeners inheriting from
  * AbstractAuthenticationListener.
  *
  * @param Request $request
  * @param AuthenticationException $exception
  *
  * @return Response The response to return, never null
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $data = array('code' => self::RESPONSE_FAILURE_CODE, 'message' => strtr($exception->getMessageKey(), $exception->getMessageData()));
     return new JsonResponse($data, self::RESPONSE_FAILURE_CODE);
 }
 /**
  * Called when authentication executed, but failed (e.g. wrong username password).
  *
  * This should return the Response sent back to the user, like a
  * RedirectResponse to the login page or a 403 response.
  *
  * If you return null, the request will continue, but the user will
  * not be authenticated. This is probably not what you want to do.
  *
  * @param Request $request
  * @param AuthenticationException $exception
  *
  * @return Response|null
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     return new JsonResponse(['message' => $this->translator->trans($exception->getMessageKey(), $exception->getMessageData())], 403);
 }