Skip to content

Commit

Permalink
attempts expiry with time
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnnajjaar committed Sep 10, 2024
1 parent 544d819 commit 061d166
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lang/en/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'invalid_length' => 'The :attribute must be 7 digits long.',
'exists' => 'The :attribute has already been taken.',
'doesnt-exist' => 'The :attribute does not exist.',
'locked' => 'The number is locked due to too many attempts.',
'locked' => 'The number is locked due to too many attempts. You can try again in :time.',
'recently_sent' => 'The code was recently sent to this number. You can try again in :time.'
],
'country_code' => [
Expand Down
5 changes: 5 additions & 0 deletions src/Models/MobileNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ public function getAttemptsExpiryAttribute(): int
return $this->can_request_code ? 0 : $this->attempts_expiry_at->diffInMinutes();
}

public function getAttemptsExpirySecondsAttribute(): int
{
return $this->can_request_code ? 0 : $this->attempts_expiry_at->diffInSeconds();
}

/**
* Verify verification_code
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Rules/IsValidMobileNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public function validate(string $attribute, mixed $value, Closure $fail): void

if ($mobile_number && $this->can_send_otp) {
if (! $mobile_number->can_request_code) {
$fail(trans('mobile-verification::strings.validation.number.locked'));
$attempts_expiry_seconds = seconds_to_human_readable($mobile_number->attempts_expiry_seconds);
$fail(trans('mobile-verification::strings.validation.number.locked', ['time' => $attempts_expiry_seconds]));
}

if ($mobile_number->was_sent_recently) {
Expand Down

0 comments on commit 061d166

Please sign in to comment.