2023-07-31 08:35:40 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2024-09-22 21:14:31 +03:00
|
|
|
use Illuminate\Auth\Access\AuthorizationException;
|
|
|
|
use Illuminate\Auth\Events\Verified;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
2023-07-31 08:35:40 +03:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
class VerificationController extends Controller
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Email Verification Controller
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
| This controller is responsible for handling email verification for any
|
|
|
|
| user that recently registered with the application. Emails may also
|
|
|
|
| be re-sent if the user didn't receive the original email message.
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Where to redirect users after verification.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected string $redirectTo = 'user/administration';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
$this->middleware('signed')->only('verify');
|
|
|
|
$this->middleware('throttle:6,1')->only('verify', 'resend');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the email verification notice.
|
|
|
|
*
|
2024-09-22 21:14:31 +03:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
2023-07-31 08:35:40 +03:00
|
|
|
*/
|
|
|
|
public function show(Request $request): View|RedirectResponse
|
|
|
|
{
|
|
|
|
return $request->user()->hasVerifiedEmail()
|
|
|
|
? redirect($this->redirectPath())
|
|
|
|
: view('user/registration/verification-notice');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:14:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark the authenticated user's email address as verified.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
|
|
|
public function verify(Request $request)
|
|
|
|
{
|
|
|
|
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->redirectPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->user()->markEmailAsVerified()) {
|
|
|
|
event(new Verified($request->user()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($response = $this->verified($request)) {
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $request->wantsJson()
|
|
|
|
? new JsonResponse([], 204)
|
|
|
|
: redirect($this->redirectPath())->with('verified', true);
|
|
|
|
}
|
|
|
|
|
2023-07-31 08:35:40 +03:00
|
|
|
/**
|
|
|
|
* The user has been verified.
|
|
|
|
*
|
2024-09-22 21:14:31 +03:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return mixed
|
2023-07-31 08:35:40 +03:00
|
|
|
*/
|
2024-09-22 21:14:31 +03:00
|
|
|
protected function verified(Request $request): mixed
|
2023-07-31 08:35:40 +03:00
|
|
|
{
|
|
|
|
return view('user/registration/registration-success');
|
|
|
|
}
|
2024-09-22 21:14:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resend the email verification notification.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function resend(Request $request)
|
|
|
|
{
|
|
|
|
if ($request->user()->hasVerifiedEmail()) {
|
|
|
|
return $request->wantsJson()
|
|
|
|
? new JsonResponse([], 204)
|
|
|
|
: redirect($this->redirectPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
$request->user()->sendEmailVerificationNotification();
|
|
|
|
|
|
|
|
return $request->wantsJson()
|
|
|
|
? new JsonResponse([], 202)
|
|
|
|
: back()->with('resent', true);
|
|
|
|
}
|
2023-07-31 08:35:40 +03:00
|
|
|
}
|