Delete expires ots & add duration to create
This commit is contained in:
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user