Files
ppeasy_vg12/app/Http/Controllers/Web/Auth/VerificationController.php
T
2026-10-09 08:21:06 +02:00

94 lines
2.7 KiB
PHP

<?php
namespace App\Http\Controllers\Web\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\Events\Verified;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response as InertiaResponse;
/**
* Handles email verification.
*
* This behaviour came from laravel/ui's VerifiesEmails trait, inlined here so
* the package is no longer a dependency.
*/
class VerificationController extends Controller
{
/**
* Where to redirect users after verification.
*/
protected string $redirectTo = '/';
public function __construct()
{
$this->middleware('auth');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
/**
* Display the email verification notice.
*/
public function show(Request $request): InertiaResponse|RedirectResponse
{
return $request->user()->hasVerifiedEmail()
? redirect($this->redirectTo)
: Inertia::render('auth/VerifyEmail', [
'resent' => (bool) $request->session()->get('resent'),
]);
}
/**
* Mark the authenticated user's email address as verified.
*
* @throws AuthorizationException
*/
public function verify(Request $request): RedirectResponse|JsonResponse
{
if (! hash_equals((string) $request->route('id'), (string) $request->user()->getKey())) {
throw new AuthorizationException;
}
if (! hash_equals((string) $request->route('hash'), sha1($request->user()->getEmailForVerification()))) {
throw new AuthorizationException;
}
if ($request->user()->hasVerifiedEmail()) {
return $request->wantsJson()
? new JsonResponse([], 204)
: redirect($this->redirectTo);
}
if ($request->user()->markEmailAsVerified()) {
event(new Verified($request->user()));
}
return $request->wantsJson()
? new JsonResponse([], 204)
: redirect($this->redirectTo)->with('verified', true);
}
/**
* Resend the email verification notification.
*/
public function resend(Request $request): RedirectResponse|JsonResponse
{
if ($request->user()->hasVerifiedEmail()) {
return $request->wantsJson()
? new JsonResponse([], 204)
: redirect($this->redirectTo);
}
$request->user()->sendEmailVerificationNotification();
return $request->wantsJson()
? new JsonResponse([], 202)
: back()->with('resent', true);
}
}