public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         //todo:
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
 /**
  * {@inheritDoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         return new Response(json_encode(array('has_error' => true, 'error' => $this->translator->trans($exception->getMessage()))));
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
 /**
  * {@inheritdoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         return new JsonResponse(['success' => false, 'message' => $exception->getMessageKey()], 401);
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
 /**
  * {@inheritDoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         $json = array('has_error' => true, 'error' => $exception->getMessage());
         return new JsonResponse($json);
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
 /**
  * {@inheritDoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest() || $request->getRequestFormat() !== 'html') {
         $json = array('code' => 401, 'message' => $this->translator->trans($exception->getMessage()));
         return new Response(json_encode($json), 401);
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
 /**
  * @param Request $request
  * @param AuthenticationException $exception
  *
  * @return Response
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         $content = array('success' => false, 'message' => $exception->getMessage());
         return new JsonResponse($content, 400);
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($exception instanceof InitializationException) {
         $username = $request->request->get('_username');
         return new RedirectResponse($this->router->generate('first_login', array('username' => $username)));
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
 /**
  * {@inheritDoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         $response = new JsonResponse(array('code' => 400, 'message' => $exception->getMessage()));
     } else {
         $response = parent::onAuthenticationFailure($request, $exception);
     }
     return $response;
 }
 /**
  * {@inheritdoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($exception instanceof BadCredentialsException) {
         if (null !== $this->logger) {
             $username = $request->request->get('_username');
             $this->logger->error($exception->getMessage(), ['username' => $username]);
         }
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $response = parent::onAuthenticationFailure($request, $exception);
     $session = $request->getSession();
     $responseType = $session->get('responseType');
     $redirectUrl = $session->get('redirectUrl');
     if ($responseType !== null) {
         $response = new RedirectResponse($this->router->generate('fos_user_security_login', array('response_type' => $responseType, 'redirect_url' => $redirectUrl)));
     }
     return $response;
 }
Beispiel #11
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)
 {
     $message = $this->translator->trans($exception->getMessage());
     if ($request->isXmlHttpRequest()) {
         $content = array('success' => false, 'message' => $message);
         return new JsonResponse($content, 400);
     }
     $request->getSession()->set('_target_path', $request->request->get('_target_path'));
     $username = $request->request->get('_username');
     $this->getLogService()->info('user', 'login_fail', "用户名:{$username},登录失败:{$message}");
     return parent::onAuthenticationFailure($request, $exception);
 }
 /**
  * {@inheritDoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         $error = explode('\\', get_class($exception));
         $error = strtolower(array_pop($error));
         $json = array('ok' => false, 'errno' => $exception->getCode(), 'error' => $error, 'message' => $exception->getMessage(), 'type' => 'login[username]');
         if ($exception instanceof \Symforce\UserBundle\Exception\CaptchaException) {
             $json['type'] = 'login[captcha][code]';
         }
         return new \Symfony\Component\HttpFoundation\JsonResponse($json);
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if (true === $request->isXmlHttpRequest()) {
         return new JsonResponse(array('success' => false, 'status' => 'failure', 'message' => $exception->getMessage() . '!'));
     }
     //default redirect operation.
     //  echo $request->getLocale();
     if ($request->getLocale() and strlen($request->getLocale()) > 0) {
         $this->options['login_path'] = '/' . $request->getLocale() . '/login';
     } else {
         $this->options['login_path'] = '/login';
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
Beispiel #15
0
 /**
  *
  * @access public
  * @param  \Symfony\Component\HttpFoundation\Request                                                     $request
  * @param  \Symfony\Component\Security\Core\Exception\AuthenticationException                            $exception
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     // Get the visitors IP address and attempted username.
     $ipAddress = $request->getClientIp();
     if ($request->request->has('_username')) {
         $username = $request->request->get('_username');
     } else {
         $username = '';
     }
     // Make a note of the failed login.
     $this->loginFailureTracker->addAttempt($ipAddress, $username);
     // Let Symfony decide what to do next
     return parent::onAuthenticationFailure($request, $exception);
 }
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         $message = $exception->getMessageKey();
         $messageTrans = $this->translator->trans($message, array(), 'FOSUserBundle');
         if ($messageTrans === $message) {
             $messageTrans = $this->translator->trans($message, array(), 'security');
         }
         $data = array('message' => $messageTrans);
         $response = new \Symfony\Component\HttpFoundation\JsonResponse($data, 400);
         return $response;
     } else {
         return parent::onAuthenticationFailure($request, $exception);
     }
 }
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $em = $this->container->get('doctrine')->getManager();
     // Decides the user provider according to domain host
     if ($request->server->get('HTTP_HOST') == $this->container->getParameter('domain_admin')) {
         $userRepo = $em->getRepository('AppFrontBundle:Professional');
     } else {
         $userRepo = $em->getRepository('AppFrontBundle:Consumer');
     }
     // Check the user instance with the username
     $user = $userRepo->findUserByUsername($request->get('_username'));
     $clientIp = $request->server->get('REMOTE_ADDR');
     if ($user instanceof User) {
         // check is the user locked or not ?
         if (!$user->isAccountNonLocked()) {
             if ($this->container->get('security.password_encoder')->isPasswordValid($user, $request->get('_password'))) {
                 $error_msg = $this->container->get('translator')->trans('login.messages.locked');
             } else {
                 $error_msg = $this->container->get('translator')->trans('login.messages.invalid');
             }
         } else {
             // creates new failure entry
             $failure = new Loginfailure();
             $failure->setUser($user);
             $failure->setIp($clientIp);
             $failure->setFailedOn(new \Datetime('now'));
             $em->persist($failure);
             // fetches last 30 minutes failure count and set the userlock
             $failureRepo = $em->getRepository('AppFrontBundle:Loginfailure');
             $failures = $failureRepo->getRecentFailures($user, $clientIp);
             if (count($failures) >= self::MAX_FAILURES) {
                 $userlock = new Userlock();
                 $userlock->setIp($clientIp);
                 $userlock->setUser($user);
                 $userlock->setLockedOn(new \Datetime('now'));
                 $em->persist($userlock);
                 $error_msg = $this->container->get('translator')->trans('login.messages.max_tries');
             } else {
                 $error_msg = $this->container->get('translator')->trans('login.messages.invalid');
             }
             $em->flush();
         }
     } else {
         $error_msg = $this->container->get('translator')->trans('login.messages.invalid');
     }
     $request->getSession()->getFlashBag()->add('login_error', $error_msg);
     return parent::onAuthenticationFailure($request, $exception);
 }
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $repo = $this->em->getRepository('UsuarioBundle:Usuario');
     $usuario = $repo->findOneBy(array('dni' => $request->get('_username')));
     /* @var $usuario Usuario */
     if ($usuario) {
         $loginAttempts = $usuario->getLoginAttempts();
         if ($loginAttempts > 3) {
             $usuario->setActivo(false);
         } else {
             $usuario->setLoginAttempts($loginAttempts + 1);
         }
         $this->em->persist($usuario);
         $this->em->flush();
         $exception = new AuthenticationException("hola");
         return parent::onAuthenticationFailure($request, $exception);
     }
 }
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $request->getSession()->set('_target_path', $request->request->get('_target_path'));
     if ($exception->getMessage() == "Bad credentials") {
         $message = "用户名或密码错误";
     } else {
         goto end;
     }
     $default = array('temporary_lock_enabled' => 0, 'temporary_lock_allowed_times' => 5, 'ip_temporary_lock_allowed_times' => 20, 'temporary_lock_minutes' => 20);
     $setting = $this->getSettingService()->get('login_bind', array());
     $setting = array_merge($default, $setting);
     if (empty($setting['temporary_lock_enabled'])) {
         goto end;
     }
     $forbidden = AuthenticationHelper::checkLoginForbidden($request);
     if ($forbidden['status'] == 'error') {
         $message = $forbidden['message'];
         $exception = new AuthenticationException($message);
     } else {
         $failed = $this->getUserService()->markLoginFailed($forbidden['user'] ? $forbidden['user']['id'] : 0, $request->getClientIp());
         if ($forbidden['user']) {
             if ($failed['ipFaildCount'] >= $setting['ip_temporary_lock_allowed_times']) {
                 $message = "您当前IP下帐号或密码输入错误过多,请在{$setting['temporary_lock_minutes']}分钟后再试。";
             } elseif ($failed['leftFailedCount']) {
                 $message = "帐号或密码错误,您还有{$failed['leftFailedCount']}次输入机会";
             } else {
                 $message = "帐号或密码输入错误过多,请在{$setting['temporary_lock_minutes']}分钟后再试,您可以通过找回并重置密码来解除封禁。";
             }
             $exception = new AuthenticationException($message);
         } else {
             $message = $exception->getMessage();
         }
     }
     end:
     if ($request->isXmlHttpRequest()) {
         $content = array('success' => false, 'message' => $message);
         return new JsonResponse($content, 400);
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
 /**
  * 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
  */
 function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     // log failed attepts
     //\LoginAttempts::RecordLoginAttempt();
     return parent::onAuthenticationFailure($request, $exception);
 }
 public function testFailurePathParameterCanBeOverwritten()
 {
     $options = array('failure_path_parameter' => '_my_failure_path');
     $this->request->expects($this->once())->method('get')->with('_my_failure_path', null, true)->will($this->returnValue('/auth/login'));
     $this->httpUtils->expects($this->once())->method('createRedirectResponse')->with($this->request, '/auth/login');
     $handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, $options, $this->logger);
     $handler->onAuthenticationFailure($this->request, $this->exception);
 }