Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RequestThrottler.php
Go to the documentation of this file.
1 <?php
8 
13 
18 {
22  const USER_TYPE_CUSTOMER = 2;
23  const USER_TYPE_ADMIN = 3;
27  private $requestLogReader;
28 
32  private $requestLogWriter;
33 
37  private $requestLogConfig;
38 
46  public function __construct(
47  RequestLogReader $requestLogReader,
48  RequestLogWriter $requestLogWriter,
49  RequestLogConfig $requestLogConfig
50  ) {
51  $this->requestLogReader = $requestLogReader;
52  $this->requestLogWriter = $requestLogWriter;
53  $this->requestLogConfig = $requestLogConfig;
54  }
55 
64  public function throttle($userName, $userType)
65  {
66  $count = $this->requestLogReader->getFailuresCount($userName, $userType);
67  if ($count >= $this->requestLogConfig->getMaxFailuresCount()) {
68  throw new AuthenticationException(
69  __(
70  'The account sign-in was incorrect or your account is disabled temporarily. '
71  . 'Please wait and try again later.'
72  )
73  );
74  }
75  }
76 
86  public function resetAuthenticationFailuresCount($userName, $userType)
87  {
88  $this->requestLogWriter->resetFailuresCount($userName, $userType);
89  }
90 
100  public function logAuthenticationFailure($userName, $userType)
101  {
102  $this->requestLogWriter->incrementFailuresCount($userName, $userType);
103  }
104 }
$count
Definition: recent.phtml:13
__()
Definition: __.php:13
__construct(RequestLogReader $requestLogReader, RequestLogWriter $requestLogWriter, RequestLogConfig $requestLogConfig)