/** * * TODO: Add Recaptcha, but first: * * add recaptcha config to newscoop preferences not in recaptcha plugin config * * remove old recaptcha libraries * * reenable failed logins counter here Newscoop\NewscoopBundle\Security\Http\Authentication\AuthenticationFailedHandler * * clean code * * {@inheritdoc} */ protected function attemptAuthentication(Request $request) { if ($request->request->has('captcha_code', $request->query->has('captcha_code')) && \LoginAttempts::MaxLoginAttemptsExceeded()) { if (false) { throw new AuthenticationException($translator->trans("CAPTCHA code is not valid. Please try again.", array(), 'home')); } } return parent::attemptAuthentication($request); }
protected function attemptAuthentication(Request $request) { // check for a valid captcha here // I am using the GregwarCaptchaBundle // only shown when throttling in my case $captcha = $request->request->get('login[recaptcha]', null, true); if (null !== $captcha) { $check = $request->getSession()->get('gcb_recaptcha'); if ($captcha !== $check['phrase']) { throw new BadCredentialsException('Captcha is invalid'); } } return parent::attemptAuthentication($request); }
protected function attemptAuthentication(Request $request) { $options = $this->getFilter($request); $accessSession = $this->registerAttempt($request); $request->getSession()->set(Security::LAST_USERNAME, $options['username']); $formType = 'LoginCidadao\\CoreBundle\\Form\\Type\\LoginFormType'; $check_captcha = $accessSession->getVal() >= $this->bruteForceThreshold; $form = $this->formFactory->create($formType, null, compact('check_captcha')); $form->handleRequest($request); if (!$form->isValid()) { $translator = $this->translator; foreach ($form->getErrors() as $error) { if ($error->getOrigin()->getName() === 'recaptcha') { throw new RecaptchaException($error->getMessage()); } throw new BadCredentialsException($translator->trans($error->getMessage())); } throw new BadCredentialsException(); } return parent::attemptAuthentication($request); }