Exemple #1
1
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     $conn = $app['phraseanet.appbox']->get_connection();
     $sql = 'SELECT date, login, ip, locked
             FROM badlog
             ORDER BY id ASC';
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $n = 1;
     foreach ($rs as $row) {
         $date = Datetime::createFromFormat('Y-m-d h:i:s', $row['date']);
         $failure = new AuthFailure();
         if ($date) {
             $failure->setCreated($date);
         }
         $failure->setIp($row['ip']);
         $failure->setLocked(!!$row['locked']);
         $failure->setUsername($row['login']);
         $app['EM']->persist($failure);
         if (0 === $n++ % 1000) {
             $app['EM']->flush();
             $app['EM']->clear();
         }
     }
     $app['EM']->flush();
     $app['EM']->clear();
     return true;
 }
 /**
  * Saves an authentication failure
  *
  * @param string  $username
  * @param Request $request
  *
  * @return FailureManager
  */
 public function saveFailure($username, Request $request)
 {
     $this->removeOldFailures();
     $failure = new AuthFailure();
     $failure->setIp($request->getClientIp());
     $failure->setUsername($username);
     $failure->setLocked(true);
     $this->em->persist($failure);
     $this->em->flush();
     return $this;
 }
 private function insertAuthFailures(EntityManager $em, \Pimple $DI)
 {
     $ip = '192.168.16.178';
     $username = '******';
     for ($i = 0; $i < 10; $i++) {
         $failure = new AuthFailure();
         $failure->setIp($ip);
         $failure->setUsername($username);
         $failure->setLocked(false);
         $failure->setCreated(new \DateTime('-3 months'));
         $em->persist($failure);
     }
     for ($i = 0; $i < 2; $i++) {
         $failure = new AuthFailure();
         $failure->setIp($ip);
         $failure->setUsername($username);
         $failure->setLocked(false);
         $failure->setCreated(new \DateTime('-1 months'));
         $em->persist($failure);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function setUsername($username)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setUsername', array($username));
     return parent::setUsername($username);
 }