1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* NOTICE OF LICENSE |
5
|
|
|
* |
6
|
|
|
* Part of the Rinvex Fort Package. |
7
|
|
|
* |
8
|
|
|
* This source file is subject to The MIT License (MIT) |
9
|
|
|
* that is bundled with this package in the LICENSE file. |
10
|
|
|
* |
11
|
|
|
* Package: Rinvex Fort Package |
12
|
|
|
* License: The MIT License (MIT) |
13
|
|
|
* Link: https://rinvex.com |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Http\Controllers\Frontend; |
17
|
|
|
|
18
|
|
|
use Illuminate\Support\Facades\Lang; |
19
|
|
|
use Rinvex\Fort\Http\Requests\EmailVerification; |
20
|
|
|
use Rinvex\Fort\Http\Controllers\AbstractController; |
21
|
|
|
use Rinvex\Fort\Contracts\VerificationBrokerContract; |
22
|
|
|
|
23
|
|
|
class EmailVerificationController extends AbstractController |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Show the email verification request form. |
27
|
|
|
* |
28
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
public function showEmailVerificationRequest() |
31
|
|
|
{ |
32
|
|
|
return view('rinvex.fort::verification.email.request'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Process the email verification request form. |
37
|
|
|
* |
38
|
|
|
* @param \Rinvex\Fort\Http\Requests\EmailVerification $request |
39
|
|
|
* |
40
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
41
|
|
|
*/ |
42
|
|
|
public function processEmailVerificationRequest(EmailVerification $request) |
43
|
|
|
{ |
44
|
|
|
$result = app('rinvex.fort.verifier') |
45
|
|
|
->broker($this->getBroker()) |
46
|
|
|
->sendVerificationLink($request->except('_token')); |
47
|
|
|
|
48
|
|
|
switch ($result) { |
49
|
|
|
case VerificationBrokerContract::LINK_SENT: |
50
|
|
|
return intend([ |
51
|
|
|
'intended' => route('home'), |
52
|
|
|
'with' => ['rinvex.fort.alert.success' => Lang::get($result)], |
53
|
|
|
]); |
54
|
|
|
|
55
|
|
|
default: |
56
|
|
|
return intend([ |
57
|
|
|
'back' => true, |
58
|
|
|
'withInput' => $request->only('email'), |
59
|
|
|
'withErrors' => ['email' => Lang::get($result)], |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Process the email verification. |
66
|
|
|
* |
67
|
|
|
* @param \Rinvex\Fort\Http\Requests\EmailVerification $request |
68
|
|
|
* |
69
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
70
|
|
|
*/ |
71
|
|
|
public function processEmailVerification(EmailVerification $request) |
72
|
|
|
{ |
73
|
|
|
$result = app('rinvex.fort.verifier')->broker($this->getBroker())->verify($request->except('_token')); |
74
|
|
|
|
75
|
|
|
switch ($result) { |
76
|
|
|
case VerificationBrokerContract::EMAIL_VERIFIED: |
77
|
|
|
return intend([ |
78
|
|
|
'intended' => route('home'), |
79
|
|
|
'with' => ['rinvex.fort.alert.success' => Lang::get($result)], |
80
|
|
|
]); |
81
|
|
|
|
82
|
|
|
case VerificationBrokerContract::INVALID_USER: |
83
|
|
|
return intend([ |
84
|
|
|
'intended' => route('rinvex.fort.verification.email'), |
85
|
|
|
'withInput' => $request->only('email'), |
86
|
|
|
'withErrors' => ['email' => Lang::get($result)], |
87
|
|
|
]); |
88
|
|
|
|
89
|
|
|
case VerificationBrokerContract::INVALID_TOKEN: |
90
|
|
|
default: |
91
|
|
|
return intend([ |
92
|
|
|
'intended' => route('rinvex.fort.verification.email'), |
93
|
|
|
'withInput' => $request->only('email'), |
94
|
|
|
'withErrors' => ['token' => Lang::get($result)], |
95
|
|
|
]); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.