Delete expires ots & add duration to create
CI/CD / test_and_check_app (push) Failing after 53s
CI/CD / Publish immutable image (push) Skipped

This commit is contained in:
2026-10-13 09:56:53 +02:00
parent 8fadceabed
commit ec93510f4b
7 changed files with 106 additions and 24 deletions
+21 -5
View File
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Enums\OneTimeSecretDuration;
use App\Http\Requests\StoreOTSRequest;
use App\Models\OneTimeSecret;
use Illuminate\Http\JsonResponse;
@@ -29,7 +30,10 @@ class OTSController extends Controller
{
$validated = $request->validated();
$ots = OneTimeSecret::create(($validated + ['expires_at' => now()->addMinutes(30)]));
$ots = OneTimeSecret::create([
'secret' => $validated['secret'],
'expires_at' => now()->addSeconds($validated['duration']),
]);
$otsLink = route('ots.show', ['oneTimeSecret' => $ots->id]);
return redirect()->route('ots.created')->with(['otsLink' => $otsLink]);
@@ -37,19 +41,31 @@ class OTSController extends Controller
public function create(): Response
{
return Inertia::render('ots/Create', []);
return Inertia::render('ots/Create', [
'durations' => array_map(
fn (OneTimeSecretDuration $duration): array => [
'value' => $duration->value,
'label' => $duration->label(),
],
OneTimeSecretDuration::cases(),
),
]);
}
public function show(OneTimeSecret $oneTimeSecret): Response
public function show(OneTimeSecret $oneTimeSecret): Response|RedirectResponse
{
if ($oneTimeSecret->expires_at->isPast()) {
$oneTimeSecret->delete();
return redirect()->route('ots.create');
}
return Inertia::render('ots/Show', ['oneTimeSecretId' => $oneTimeSecret->id]);
}
public function reveal(OneTimeSecret $oneTimeSecret): JsonResponse
public function reveal(OneTimeSecret $oneTimeSecret): JsonResponse|RedirectResponse
{
$oneTimeSecret->delete();
if ($oneTimeSecret->expires_at->isPast()) {
abort(404);
return redirect()->route('ots.create');
}
return response()->json(['secret' => $oneTimeSecret->secret]);