From d81e60da1e30c38a089c38cc7f178fd9bb3de8cb Mon Sep 17 00:00:00 2001 From: Derek Pollard Date: Thu, 26 Aug 2021 11:02:09 -0500 Subject: [PATCH] Add in the action to the snaptcha logs --- src/services/SnaptchaService.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/services/SnaptchaService.php b/src/services/SnaptchaService.php index 27f9b9a..b88233f 100644 --- a/src/services/SnaptchaService.php +++ b/src/services/SnaptchaService.php @@ -175,10 +175,12 @@ public function isTooSoon(SnaptchaRecord $record): bool * * @return bool */ - public function validateField(string $value = null): bool + public function validateField(string $value = null, Action $action = null): bool { // Fire a before event $event = new ValidateFieldEvent(['value' => $value]); + $actionName = $action ? $action->getUniqueId() : 'NO_ACTION'; + $this->trigger(self::EVENT_BEFORE_VALIDATE_FIELD, $event); if ($event->skipValidation) { @@ -200,7 +202,7 @@ public function validateField(string $value = null): bool } if ($value === null) { - $this->_reject('Value submitted is null.'); + $this->_reject('{actionName} - Value submitted is null.', ['actionName' => $actionName]); return false; } @@ -221,21 +223,27 @@ public function validateField(string $value = null): bool ->one(); if ($record === null) { - $this->_reject('Value not found in database.'); + $this->_reject('{actionName} - Value not found in database.', ['actionName' => $actionName]); return false; } // Check if field has expired if ($this->isExpired($record)) { - $this->_reject('Expiration time of {minutes} minute(s) has passed.', ['minutes' => $record->expirationTime]); + $this->_reject( + '{actionName} - Expiration time of {minutes} minute(s) has passed.', + ['minutes' => $record->expirationTime, 'actionName' => $actionName] + ); return false; } // Check if minimum submit time has not passed if ($this->isTooSoon($record)) { - $this->_reject('Minimum submit time of {second} second(s) has not yet passed.', ['second' => $record->minimumSubmitTime]); + $this->_reject( + '{actionName} - Minimum submit time of {second} second(s) has not yet passed.', + ['second' => $record->minimumSubmitTime, 'actionName' => $actionName] + ); return false; }