29 lines
684 B
PHP
Executable File
29 lines
684 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Validation;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
class MathCaptchaRule implements Rule
|
|
{
|
|
public function passes($attribute, $value): bool
|
|
{
|
|
if (!Session::has('math_captcha_answer')) {
|
|
return false;
|
|
}
|
|
|
|
$expected = Session::get('math_captcha_answer');
|
|
|
|
Session::forget('math_captcha_answer');
|
|
Session::forget('math_captcha_question');
|
|
|
|
return $value !== null && $value !== '' && (int) $value === (int) $expected;
|
|
}
|
|
|
|
public function message(): string
|
|
{
|
|
return __('The captcha answer is incorrect. Please try again.');
|
|
}
|
|
}
|