1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Http\Controllers\Auth; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Http\Requests\EmailVerificationRequest; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Illuminate\Routing\Controller; |
8
|
|
|
use Prologue\Alerts\Facades\Alert; |
9
|
|
|
use Throwable; |
10
|
|
|
use Exception; |
11
|
|
|
|
12
|
|
|
class VerifyEmailController extends Controller |
13
|
|
|
{ |
14
|
|
|
public null|string $redirectTo = null; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Create a new controller instance. |
18
|
|
|
* |
19
|
|
|
* @return void |
20
|
|
|
*/ |
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
$this->middleware(backpack_middleware()); |
24
|
|
|
|
25
|
|
|
try { |
26
|
|
|
$signedMiddleware = new (app('router')->getMiddleware()['signed'])(); |
|
|
|
|
27
|
|
|
}catch(Throwable) { |
28
|
|
|
throw new Exception('Missing "signed" alias middleware in App/Http/Kernel.php. More info: https://backpackforlaravel.com/docs/6.x/base-how-to#enable-email-verification-in-backpack-routes'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$this->middleware($signedMiddleware)->only('verifyEmail'); |
32
|
|
|
$this->middleware('throttle:'.config('backpack.base.email_verification_throttle_access'))->only('resendVerificationEmail'); |
33
|
|
|
|
34
|
|
|
if (! backpack_users_have_email()) { |
35
|
|
|
abort(500, trans('backpack::base.no_email_column')); |
36
|
|
|
} |
37
|
|
|
// where to redirect after the email is verified |
38
|
|
|
$this->redirectTo = $this->redirectTo !== null ? $this->redirectTo : backpack_url('dashboard'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function emailVerificationRequired(): \Illuminate\Contracts\View\View |
42
|
|
|
{ |
43
|
|
|
return view(backpack_view('auth.verify-email')); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Verify the user's email address. |
48
|
|
|
* |
49
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
50
|
|
|
*/ |
51
|
|
|
public function verifyEmail(EmailVerificationRequest $request) |
52
|
|
|
{ |
53
|
|
|
$request->fulfill(); |
54
|
|
|
|
55
|
|
|
return redirect($this->redirectTo); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Resend the email verification notification. |
60
|
|
|
*/ |
61
|
|
|
public function resendVerificationEmail(Request $request): \Illuminate\Http\RedirectResponse |
62
|
|
|
{ |
63
|
|
|
$request->user(backpack_guard_name())->sendEmailVerificationNotification(); |
64
|
|
|
|
65
|
|
|
Alert::success('Email verification link sent successfully.')->flash(); |
66
|
|
|
|
67
|
|
|
return back()->with('status', 'verification-link-sent'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|