public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $login = new \Club\UserBundle\Entity\LoginAttempt();
     $login->setUsername($request->get('_username'));
     $login->setSession($request->getSession()->getId());
     $login->setIpAddress($request->getClientIp());
     $login->setHostname(gethostbyaddr($request->getClientIp()));
     $login->setLoginFailed(1);
     $this->em->persist($login);
     $this->em->flush();
     return new RedirectResponse('login');
 }
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     $login = new \Club\UserBundle\Entity\LoginAttempt();
     $login->setUsername($request->get('_username'));
     $login->setSession($request->getSession()->getId());
     $login->setIpAddress($request->getClientIp());
     $login->setHostname(gethostbyaddr($request->getClientIp()));
     $login->setLoginFailed(0);
     $this->em->persist($login);
     $this->em->flush();
     return new RedirectResponse('user');
 }
Esempio n. 3
0
 public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
 {
     $user = $this->em->find('ClubUserBundle:User', $this->security_context->getToken()->getUser()->getId());
     $user->setLastLoginTime(new \DateTime());
     $user->setLastLoginIp($event->getRequest()->getClientIp());
     if (!strlen($user->getApiHash())) {
         $user->setApiHash($user->generateKey());
     }
     $this->em->persist($user);
     $login = new \Club\UserBundle\Entity\LoginAttempt();
     $login->setUsername($user->getUsername());
     $login->setSession(session_id());
     $login->setIpAddress($event->getRequest()->getClientIp());
     $login->setHostname(gethostbyaddr($event->getRequest()->getClientIp()));
     $login->setLoginFailed(0);
     $this->em->persist($login);
     $this->em->flush();
     $this->setLocation($event);
     $this->setLocale($event);
     $this->checkin($event);
     $reset = $this->em->createQueryBuilder()->select('r')->from('ClubUserBundle:ResetPassword', 'r')->where('r.user = :user')->setParameter('user', $user->getId())->getQuery()->getOneOrNullResult();
 }