Added OTS create,store,show
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StoreOTSRequest;
|
||||
use App\Models\OneTimeSecret;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class OTSController extends Controller
|
||||
{
|
||||
public function store(StoreOTSRequest $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
OneTimeSecret::create(($validated + ['expires_at' => now()->addMinutes(30)]));
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
public function create(): Response
|
||||
{
|
||||
return Inertia::render('ots/Create');
|
||||
}
|
||||
|
||||
public function show(OneTimeSecret $oneTimeSecret): Response
|
||||
{
|
||||
$oneTimeSecret->delete();
|
||||
|
||||
return Inertia::render('ots/Show', ['oneTimeSecret' => $oneTimeSecret]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreOTSRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'secret' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user