17dd5acd23
Implements T1.1-T1.4: Spatie role/permission seeding, Sanctum token issuance for customer channels and the FastAPI agent (with an ability-exact-match middleware to tell them apart), Filament admin panel access restricted to admin-tier roles with the navigation group order, and skeleton BookingPolicy/RoutePolicy gated on the seeded permissions ahead of their models landing in later phases.
38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\Identity\Http\Controllers;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Modules\Identity\Enums\TokenAbility;
|
|
use Modules\Identity\Http\Requests\IssueTokenRequest;
|
|
|
|
class TokenController extends Controller
|
|
{
|
|
/**
|
|
* Exchange customer credentials (mini app / mobile app) for a Sanctum
|
|
* token carrying the full customer ability set.
|
|
*/
|
|
public function store(IssueTokenRequest $request): array
|
|
{
|
|
$user = User::where('email', $request->string('email'))->first();
|
|
|
|
if (! $user || ! Hash::check($request->string('password'), $user->password)) {
|
|
throw ValidationException::withMessages([
|
|
'email' => ['The provided credentials are incorrect.'],
|
|
]);
|
|
}
|
|
|
|
$token = $user->createToken(
|
|
$request->string('device_name')->toString(),
|
|
TokenAbility::customerAbilities(),
|
|
);
|
|
|
|
return [
|
|
'token' => $token->plainTextToken,
|
|
];
|
|
}
|
|
}
|