add test batches

This commit is contained in:
root
2026-06-08 23:45:55 -04:00
parent c792b8be05
commit 8d4d610b82
1480 changed files with 22587 additions and 10762 deletions
@@ -2,9 +2,9 @@
namespace App\Services\Auth;
use App\Models\Configuration;
use App\Models\IpAttempt;
use App\Models\LoginActivity;
use App\Models\Configuration;
use App\Models\User;
use Carbon\CarbonImmutable;
use Illuminate\Http\Request;
@@ -22,7 +22,7 @@ class ApiLoginSecurityService
public function isIpBlocked(string $ip): bool
{
$row = IpAttempt::query()->where('ip_address', $ip)->first();
if (! $row || ! $row->blocked_until) {
if (!$row || !$row->blocked_until) {
return false;
}
+4 -2
View File
@@ -3,11 +3,12 @@
namespace App\Services\Auth;
use App\Models\Configuration;
use App\Services\ApplicationUrlService;
use App\Models\LoginActivity;
use App\Models\Preferences;
use App\Models\Role;
use App\Models\User;
use App\Services\ApplicationUrlService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
@@ -20,7 +21,8 @@ class AuthSessionService
public function __construct(
private ApplicationUrlService $urls,
) {}
) {
}
/**
* Sanitizes login redirects to same-host relative paths only.
+1 -1
View File
@@ -12,7 +12,7 @@ class PermissionCheckService
->where('name', $permissionName)
->value('id');
if (! $permissionId) {
if (!$permissionId) {
return false;
}
@@ -9,8 +9,7 @@ class RegistrationCaptchaService
$ip = (string) (request()?->ip() ?? 'unknown');
$ua = (string) (request()?->header('User-Agent') ?? '');
$hash = substr(sha1($ua), 0, 12);
return 'captcha:'.$ip.':'.$hash;
return 'captcha:' . $ip . ':' . $hash;
}
public function generate(?int $length = null): string
@@ -6,7 +6,9 @@ use App\Services\PhoneFormatterService;
class RegistrationFormatterService
{
public function __construct(private PhoneFormatterService $phoneFormatter) {}
public function __construct(private PhoneFormatterService $phoneFormatter)
{
}
public function format(array $payload): array
{
@@ -28,7 +30,7 @@ class RegistrationFormatterService
'accept_school_policy' => (int) ($payload['accept_school_policy'] ?? 0),
];
$noSecondInfo = ! empty($payload['no_second_parent_info']);
$noSecondInfo = !empty($payload['no_second_parent_info']);
$secondFirstname = $this->formatName($g('second_firstname'));
$secondLastname = $this->formatName($g('second_lastname'));
@@ -36,7 +38,7 @@ class RegistrationFormatterService
$secondEmail = $this->formatEmail($g('second_email'));
$secondCellphone = $this->phoneFormatter->formatPhoneNumber($g('second_cellphone'));
$secondProvided = ! $noSecondInfo && (
$secondProvided = !$noSecondInfo && (
$secondFirstname !== '' ||
$secondLastname !== '' ||
$secondGender !== '' ||
@@ -62,7 +64,7 @@ class RegistrationFormatterService
return '';
}
return ucwords(strtolower($name), ' -');
return ucwords(strtolower($name), " -");
}
private function formatEmail(string $email): string
+13 -12
View File
@@ -20,12 +20,13 @@ class RegistrationService
private RegistrationFormatterService $formatter,
private RegistrationCaptchaService $captchaService,
private ApplicationUrlService $urls,
) {}
) {
}
public function register(array $payload): array
{
$captcha = (string) ($payload['captcha'] ?? '');
if (! $this->captchaService->verify($captcha)) {
if (!$this->captchaService->verify($captcha)) {
return [
'ok' => false,
'code' => 'captcha_invalid',
@@ -33,15 +34,15 @@ class RegistrationService
];
}
$isParent = ! empty($payload['is_parent']);
$noSecondInfo = ! empty($payload['no_second_parent_info']);
$isParent = !empty($payload['is_parent']);
$noSecondInfo = !empty($payload['no_second_parent_info']);
$formatted = $this->formatter->format($payload);
$email = (string) ($formatted['email'] ?? '');
$existing = User::query()->where('email', $email)->first();
if ($existing) {
$pending = ! empty($existing->token) && (int) ($existing->is_verified ?? 0) === 0;
$pending = !empty($existing->token) && (int) ($existing->is_verified ?? 0) === 0;
if ($pending) {
return [
'ok' => false,
@@ -59,7 +60,7 @@ class RegistrationService
$roleName = $isParent ? 'parent' : 'guest';
$role = Role::query()->where('name', $roleName)->first();
if (! $role) {
if (!$role) {
return [
'ok' => false,
'code' => 'role_missing',
@@ -112,7 +113,7 @@ class RegistrationService
'created_at' => now(),
]);
if ($isParent && ! $noSecondInfo && ! empty($formatted['second_firstname'])) {
if ($isParent && !$noSecondInfo && !empty($formatted['second_firstname'])) {
ParentModel::query()->create([
'secondparent_firstname' => $formatted['second_firstname'] ?? null,
'secondparent_lastname' => $formatted['second_lastname'] ?? null,
@@ -127,12 +128,12 @@ class RegistrationService
});
$activationLink = $this->urls->spaRegistrationConfirmUrl($token);
$recipientName = trim((string) ($formatted['firstname'] ?? '').' '.(string) ($formatted['lastname'] ?? ''));
$recipientName = trim((string) ($formatted['firstname'] ?? '') . ' ' . (string) ($formatted['lastname'] ?? ''));
$html = '<p>Hello '.e($recipientName !== '' ? $recipientName : 'there').',</p>'
.'<p>Please confirm your email by clicking the link below:</p>'
.'<p><a href="'.e($activationLink).'">Activate your account</a></p>'
.'<p>Thank you.</p>';
$html = '<p>Hello ' . e($recipientName !== '' ? $recipientName : 'there') . ',</p>'
. '<p>Please confirm your email by clicking the link below:</p>'
. '<p><a href="' . e($activationLink) . '">Activate your account</a></p>'
. '<p>Thank you.</p>';
$sent = $this->emailService->send($email, 'Email Confirmation', $html, 'general');
$this->captchaService->clear();
+4 -4
View File
@@ -35,16 +35,16 @@ class UserRoleService
return true;
}
if ($crudAction === 'create' && ! empty($row->can_create)) {
if ($crudAction === 'create' && !empty($row->can_create)) {
return true;
}
if ($crudAction === 'read' && ! empty($row->can_read)) {
if ($crudAction === 'read' && !empty($row->can_read)) {
return true;
}
if ($crudAction === 'update' && ! empty($row->can_update)) {
if ($crudAction === 'update' && !empty($row->can_update)) {
return true;
}
if ($crudAction === 'delete' && ! empty($row->can_delete)) {
if ($crudAction === 'delete' && !empty($row->can_delete)) {
return true;
}
}