|
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 Carbon\Carbon; |
|
19
|
|
|
use Illuminate\Support\Facades\Auth; |
|
20
|
|
|
use Rinvex\Fort\Guards\SessionGuard; |
|
21
|
|
|
use Rinvex\Fort\Http\Controllers\AbstractController; |
|
22
|
|
|
use Rinvex\Fort\Http\Requests\Frontend\PhoneVerificationRequest; |
|
23
|
|
|
use Rinvex\Fort\Http\Requests\Frontend\PhoneVerificationSendRequest; |
|
24
|
|
|
|
|
25
|
|
|
class PhoneVerificationController extends AbstractController |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Show the phone verification form. |
|
29
|
|
|
* |
|
30
|
|
|
* @param \Rinvex\Fort\Http\Requests\Frontend\PhoneVerificationSendRequest $request |
|
31
|
|
|
* |
|
32
|
|
|
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
|
|
|
|
|
33
|
|
|
*/ |
|
34
|
|
|
public function request(PhoneVerificationSendRequest $request) |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
// If Two-Factor authentication failed, remember Two-Factor persistence |
|
37
|
|
|
Auth::guard($this->getGuard())->rememberTwoFactor(); |
|
38
|
|
|
|
|
39
|
|
|
return view('rinvex/fort::frontend/verification.phone.request'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Process the phone verification request form. |
|
44
|
|
|
* |
|
45
|
|
|
* @param \Rinvex\Fort\Http\Requests\Frontend\PhoneVerificationSendRequest $request |
|
46
|
|
|
* |
|
47
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
48
|
|
|
*/ |
|
49
|
|
|
public function send(PhoneVerificationSendRequest $request) |
|
50
|
|
|
{ |
|
51
|
|
|
// Send phone verification notification |
|
52
|
|
|
$request->user($this->getGuard())->sendPhoneVerificationNotification(false, $request->get('method')); |
|
53
|
|
|
|
|
54
|
|
|
return intend([ |
|
55
|
|
|
'route' => 'rinvex.fort.frontend.verification.phone.verify', |
|
56
|
|
|
'with' => ['rinvex.fort.alert.success' => trans('rinvex/fort::frontend/messages.verification.phone.sent')], |
|
57
|
|
|
]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Show the phone verification form. |
|
62
|
|
|
* |
|
63
|
|
|
* @param \Rinvex\Fort\Http\Requests\Frontend\PhoneVerificationRequest $request |
|
64
|
|
|
* |
|
65
|
|
|
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
|
|
|
|
|
66
|
|
|
*/ |
|
67
|
|
|
public function verify(PhoneVerificationRequest $request) |
|
|
|
|
|
|
68
|
|
|
{ |
|
69
|
|
|
// If Two-Factor authentication failed, remember Two-Factor persistence |
|
70
|
|
|
Auth::guard($this->getGuard())->rememberTwoFactor(); |
|
71
|
|
|
|
|
72
|
|
|
$methods = session('rinvex.fort.twofactor.methods'); |
|
73
|
|
|
|
|
74
|
|
|
return view('rinvex/fort::frontend/verification.phone.token', compact('methods')); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Process the phone verification form. |
|
79
|
|
|
* |
|
80
|
|
|
* @param \Rinvex\Fort\Http\Requests\Frontend\PhoneVerificationRequest $request |
|
81
|
|
|
* |
|
82
|
|
|
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
83
|
|
|
*/ |
|
84
|
|
|
public function process(PhoneVerificationRequest $request) |
|
85
|
|
|
{ |
|
86
|
|
|
$guard = $this->getGuard(); |
|
87
|
|
|
$token = $request->get('token'); |
|
88
|
|
|
$user = session('rinvex.fort.twofactor.user') ?: $request->user($this->getGuard()); |
|
89
|
|
|
$result = Auth::guard($guard)->attemptTwoFactor($user, $token); |
|
90
|
|
|
|
|
91
|
|
|
switch ($result) { |
|
92
|
|
|
case SessionGuard::AUTH_PHONE_VERIFIED: |
|
93
|
|
|
// Update user account |
|
94
|
|
|
app('rinvex.fort.user')->update($user, [ |
|
95
|
|
|
'phone_verified' => true, |
|
96
|
|
|
'phone_verified_at' => new Carbon(), |
|
97
|
|
|
]); |
|
98
|
|
|
|
|
99
|
|
|
return intend([ |
|
100
|
|
|
'route' => 'rinvex.fort.frontend.user.settings', |
|
101
|
|
|
'with' => ['rinvex.fort.alert.success' => trans($result)], |
|
102
|
|
|
]); |
|
103
|
|
|
|
|
104
|
|
|
case SessionGuard::AUTH_LOGIN: |
|
105
|
|
|
Auth::guard($guard)->login($user, session('rinvex.fort.twofactor.remember'), session('rinvex.fort.twofactor.persistence')); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
return intend([ |
|
108
|
|
|
'intended' => url('/'), |
|
109
|
|
|
'with' => ['rinvex.fort.alert.success' => trans($result)], |
|
110
|
|
|
]); |
|
111
|
|
|
|
|
112
|
|
|
case SessionGuard::AUTH_TWOFACTOR_FAILED: |
|
113
|
|
|
default: |
|
114
|
|
|
// If Two-Factor authentication failed, remember Two-Factor persistence |
|
115
|
|
|
Auth::guard($guard)->rememberTwoFactor(); |
|
116
|
|
|
|
|
117
|
|
|
return intend([ |
|
118
|
|
|
'back' => true, |
|
119
|
|
|
'withInput' => $request->only(['token']), |
|
120
|
|
|
'withErrors' => ['token' => trans($result)], |
|
121
|
|
|
]); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.