-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathVerifyEmailController.php
41 lines (32 loc) · 1.12 KB
/
VerifyEmailController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Auth\Events\Verified;
use Illuminate\Http\Request;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
class VerifyEmailController extends Controller
{
/**
* Mark the authenticated user's email address as verified.
*/
public function __invoke(Request $request, int $id, string $hash): RedirectResponse
{
if (! $request->hasValidSignature()) {
abort(403, 'Invalid or expired verification link.');
}
$user = User::findOrFail($id);
if (! hash_equals($hash, sha1($user->getEmailForVerification()))) {
abort(403, 'Invalid verification hash.');
}
// Now you can verify the email
if (! $user->hasVerifiedEmail()) {
$user->markEmailAsVerified();
// Fire event when email is verified
event(new Verified($user));
}
Auth::login($user);
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
}
}