コード例 #1
0
 /**
  * Hook which sends a notification on a published notification failure
  *
  * @param AuthenticationAttemptEvent $event
  */
 public function onAuthenticationFailure(AuthenticationAttemptEvent $event)
 {
     $user = $event->getUser();
     $report = $event->getReport();
     $defaultParameters = ['user' => $user, 'override_locale' => true];
     if (1 < ($attempts = $report->getAttempts())) {
         $defaultParameters['content'] = 'notification.auth.failures';
         $defaultParameters['parameters'] = ['translation_defaults' => ['%times%' => $attempts]];
     } else {
         $defaultParameters['content'] = 'notification.auth.single_failure';
     }
     $this->publisher->createAndPublish('sen_mailer', $defaultParameters);
 }
 public function testSendNotification()
 {
     DomainEvents::setEventDispatcher(new EventDispatcher());
     $user = User::fromDTO(new CreateUserDTO('Ma27', 'test-password', '*****@*****.**'));
     $publisher = $this->getMock(BackendInterface::class);
     $publisher->expects($this->once())->method('createAndPublish')->with('sen_mailer', ['override_locale' => true, 'user' => $user, 'content' => 'notification.auth.failures', 'parameters' => ['translation_defaults' => ['%times%' => 2]]]);
     $hook = new AuthenticationReportListener($publisher);
     $entity = new AuthenticationFailure($user);
     $entity->updateReport();
     $entity->updateReport();
     $entityReport = $entity->createReport();
     $event = new AuthenticationAttemptEvent($user);
     $event->setReport($entityReport);
     $hook->onAuthenticationFailure($event);
 }
コード例 #3
0
 /**
  * Updates the failure report
  */
 public function updateReport()
 {
     if (null === $this->start) {
         $this->start = new \DateTime();
         $this->attemptCount++;
         $event = new AuthenticationAttemptEvent($this->relatedUser);
         $event->setReport($this->createReport());
         DomainEvents::raise($event);
     } else {
         $intervalTimestamp = $this->start->getTimestamp();
         if (time() - $intervalTimestamp > 86400) {
             $this->start = new \DateTime();
             $this->attemptCount = 1;
         } else {
             $this->attemptCount++;
             if (time() - $intervalTimestamp >= 21600) {
                 $event = new AuthenticationAttemptEvent($this->relatedUser);
                 $event->setReport($this->createReport());
                 DomainEvents::raise($event);
             }
         }
     }
 }