Controller/Response.php
private function processFailedRequest()
    {
        $url = $this->_url->getCurrentUrl();
        $storeId = $this->storeManager->getStore()->getId();
        $failedAuth = $this->failedAuthFactory->create();
        $this->failedAuthResource->load($failedAuth, $storeId, 'store_id');
        $numOfFails = $failedAuth->getFailuresNum();
        $lastAttemptDate = $failedAuth->getLastAttemptDate();
        //set the first failed attempt
        if (!$failedAuth->getId()) {
            $failedAuth->setFirstAttemptDate(time());
        }

        //check the time for the last fail and update the records
        if ($numOfFails == \Dotdigitalgroup\Email\Model\FailedAuth::NUMBER_MAX_FAILS_LIMIT) {
            //ignore the resource is in a locked state
            if ($failedAuth->isLocked()) {
                $this->helper->log(sprintf('Resource locked time : %s ,store : %s', $lastAttemptDate, $storeId));
                return;
            } else {
                //reset with the first lock after the the lock expired
                $numOfFails = 0;
                $failedAuth->setFirstAttemptDate(time());
            }
        }
        try {
            $failedAuth->setFailuresNum(++$numOfFails)
                ->setStoreId($storeId)
                ->setUrl($url)
                ->setLastAttemptDate(time());
            $this->failedAuthResource->save($failedAuth);
        } catch (\Exception $e) {
            $this->helper->log($e);
        }
    }
private function processFailedRequest()
    {
        $url = $this->_url->getCurrentUrl();
        $storeId = $this->storeManager->getStore()->getId();
        $failedAuth = $this->failedAuthFactory->create();
        $this->failedAuthResource->load($failedAuth, $storeId, 'store_id');
        $numOfFails = $failedAuth->getFailuresNum();
        $lastAttemptDate = $failedAuth->getLastAttemptDate();
        //set the first failed attempt
        if (!$failedAuth->getId()) {
            $failedAuth->setFirstAttemptDate(time());
        }

        //check the time for the last fail and update the records
        if ($numOfFails == \Dotdigitalgroup\Email\Model\FailedAuth::NUMBER_MAX_FAILS_LIMIT) {
            //ignore the resource is in a locked state
            if ($failedAuth->isLocked()) {
                $this->helper->log(sprintf('Resource locked time : %s ,store : %s', $lastAttemptDate, $storeId));
                return;
            } else {
                //reset with the first lock after the the lock expired
                $numOfFails = 0;
                $failedAuth->setFirstAttemptDate(time());
            }
        }
        try {
            $failedAuth->setFailuresNum(++$numOfFails)
                ->setStoreId($storeId)
                ->setUrl($url)
                ->setLastAttemptDate(time());
            $this->failedAuthResource->save($failedAuth);
        } catch (\Exception $e) {
            $this->helper->log($e);
        }
    }
private function processFailedRequest ( ) { $ url = $ this -> _url -> getCurrentUrl ( ) ; $ storeId = $ this -> storeManager -> getStore ( ) -> getId ( ) ; $ failedAuth = $ this -> failedAuthFactory -> create ( ) ; $ this -> failedAuthResource -> load ( $ failedAuth , $ storeId , 'store_id' ) ; $ numOfFails = $ failedAuth -> getFailuresNum ( ) ; $ lastAttemptDate = $ failedAuth -> getLastAttemptDate ( ) ; //set the first failed attempt if ( ! $ failedAuth -> getId ( ) ) { $ failedAuth -> setFirstAttemptDate ( time ( ) ) ; } //check the time for the last fail and update the records if ( $ numOfFails == \ Dotdigitalgroup \ Email \ Model \ FailedAuth :: NUMBER_MAX_FAILS_LIMIT ) { //ignore the resource is in a locked state if ( $ failedAuth -> isLocked ( ) ) { $ this -> helper -> log ( sprintf ( 'Resource locked time : %s ,store : %s' , $ lastAttemptDate , $ storeId ) ) ; return ; } else { //reset with the first lock after the the lock expired $ numOfFails = 0 ; $ failedAuth -> setFirstAttemptDate ( time ( ) ) ; } } try { $ failedAuth -> setFailuresNum ( ++ $ numOfFails ) -> setStoreId ( $ storeId ) -> setUrl ( $ url ) -> setLastAttemptDate ( time ( ) ) ; $ this -> failedAuthResource -> save ( $ failedAuth ) ; } catch ( \ Exception $ e ) { $ this -> helper -> log ( $ e ) ; } }
Register the failed attempt and set a lock with a 5min window if more then 5 request failed.
Register the failed attempt and set a lock with a 5min window if more then 5 request failed .