feat(scanner): add scanner authentication and context services with routes and tests

This commit is contained in:
2026-08-11 14:11:23 -03:00
parent 254faedf2c
commit 3eaa3f8202
12 changed files with 316 additions and 4 deletions

View File

@@ -62,6 +62,29 @@ class PasswordLoginService
);
}
/**
* Authenticate a tenant-bound scanner without requiring its tenant code.
*
* @throws AccountLockedException
* @throws ValidationException
*/
public function authenticateScanner(
string $email,
string $password,
?string $ipAddress,
?string $userAgent,
): User {
return $this->authenticateUser(
$email,
$password,
null,
$ipAddress,
$userAgent,
RoleCode::Scanner,
true,
);
}
private function authenticateUser(
string $email,
string $password,
@@ -210,7 +233,7 @@ class PasswordLoginService
} catch (\Throwable $e) {
Log::error('Failed to trigger reset password on account lock', [
'user_id' => $user->id,
'exception' => $e
'exception' => $e,
]);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Domains\Auth\Services;
use App\Domains\Auth\Models\User;
use App\Domains\Authorization\Enums\RoleCode;
class ScannerContextService
{
public function load(User $user): User
{
$tenant = $user->tenant()
->with([
'menues' => fn ($query) => $query->whereHas(
'roles',
fn ($query) => $query->where('codigo', RoleCode::Scanner->value)
),
])
->firstOrFail();
$user->setRelation('tenant', $tenant);
return $user;
}
}