add all controllers logic

This commit is contained in:
root
2026-03-11 17:53:15 -04:00
parent 3e6c577085
commit 2ef71cc92b
421 changed files with 12009 additions and 5211 deletions
@@ -4,6 +4,14 @@ namespace App\Services\Auth;
class RegistrationCaptchaService
{
private function cacheKey(): string
{
$ip = (string) (request()?->ip() ?? 'unknown');
$ua = (string) (request()?->header('User-Agent') ?? '');
$hash = substr(sha1($ua), 0, 12);
return 'captcha:' . $ip . ':' . $hash;
}
public function generate(?int $length = null): string
{
$length = $length ?? random_int(4, 8);
@@ -14,14 +22,14 @@ class RegistrationCaptchaService
$captchaText .= $characters[random_int(0, strlen($characters) - 1)];
}
session()->put('captcha_answer', $captchaText);
cache()->put($this->cacheKey(), $captchaText, now()->addMinutes(10));
return $captchaText;
}
public function verify(string $input): bool
{
$expected = (string) session()->get('captcha_answer', '');
$expected = (string) cache()->get($this->cacheKey(), '');
if ($expected === '') {
return false;
}
@@ -31,6 +39,6 @@ class RegistrationCaptchaService
public function clear(): void
{
session()->forget('captcha_answer');
cache()->forget($this->cacheKey());
}
}