Created
October 25, 2013 08:51
-
-
Save Tobur/7151615 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param Request $request | |
* @param AuthenticationException $exception | |
* @return \Symfony\Component\HttpFoundation\RedirectResponse | |
*/ | |
public function onAuthenticationFailure(Request $request, AuthenticationException $exception) | |
{ | |
$data = $request->request->All('_username'); | |
$username = $data['_username']; | |
$user = $this->em->getRepository('DataBundle:User')->findOneByEmail($username); | |
if ($user) { | |
$this->container->get('session')->getFlashBag()->add( | |
'error', | |
'Incorrect email or password.' | |
); | |
$defense = $user->getDefense(); | |
if ($defense) { | |
$defense->addAttempt(); | |
} else { | |
$defense = new LoginDefense(); | |
//$user->setDefense($defense); | |
$defense->setUser($user); | |
} | |
$this->em->persist($defense); | |
$this->em->flush(); | |
} else { | |
$this->container->get('session')->getFlashBag()->add( | |
'error', | |
sprintf('No user with email "%s" was found.', $username) | |
); | |
} | |
$url = $this->container->get('router')->generate('fos_user_security_login'); | |
return new RedirectResponse($url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment