Skip to content

Commit

Permalink
Add in the action to the snaptcha logs
Browse files Browse the repository at this point in the history
  • Loading branch information
d-pollard committed Aug 26, 2021
1 parent c129cdf commit d81e60d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/services/SnaptchaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit d81e60d

Please sign in to comment.