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\Requests\Frontend; |
17
|
|
|
|
18
|
|
|
use Illuminate\Support\Facades\Auth; |
19
|
|
|
use Rinvex\Support\Http\Requests\FormRequest; |
20
|
|
|
|
21
|
|
|
class PhoneVerificationRequest extends FormRequest |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function forbiddenResponse() |
27
|
|
|
{ |
28
|
|
|
$user = Auth::guard()->user(); |
29
|
|
|
$attemptUser = Auth::guard()->attemptUser(); |
30
|
|
|
|
31
|
|
|
return $user && ! $user->country ? intend([ |
32
|
|
|
// Logged in user, no country, phone verification attempt (account update) |
33
|
|
|
'route' => 'rinvex.fort.frontend.user.settings', |
34
|
|
|
'withErrors' => ['country' => trans('rinvex/fort::frontend/messages.account.country_required')], |
35
|
|
|
]) : ($attemptUser && ! $attemptUser->country ? intend([ |
36
|
|
|
// Login attempt, no country, enabled Two-Factor |
37
|
|
|
'route' => 'rinvex.fort.frontend.auth.login', |
38
|
|
|
'withErrors' => ['rinvex.fort.auth.country' => trans('rinvex/fort::frontend/messages.verification.twofactor.phone.country_required')], |
|
|
|
|
39
|
|
|
]) : intend([ |
40
|
|
|
// No login attempt, no user instance, phone verification attempt |
41
|
|
|
'route' => 'rinvex.fort.frontend.auth.login', |
42
|
|
|
'withErrors' => ['rinvex.fort.auth.required' => trans('rinvex/fort::frontend/messages.auth.session.required')], |
|
|
|
|
43
|
|
|
])); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function response(array $errors) |
50
|
|
|
{ |
51
|
|
|
// If we've got errors, remember Two-Factor persistence |
52
|
|
|
Auth::guard()->rememberTwoFactor(); |
53
|
|
|
|
54
|
|
|
return parent::response($errors); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Determine if the user is authorized to make this request. |
59
|
|
|
* |
60
|
|
|
* @return bool |
61
|
|
|
*/ |
62
|
|
|
public function authorize() |
63
|
|
|
{ |
64
|
|
|
$user = Auth::guard()->user() ?: Auth::guard()->attemptUser(); |
65
|
|
|
$providers = config('rinvex.fort.twofactor.providers'); |
66
|
|
|
|
67
|
|
|
return ! $user || ! $user->country || ! in_array('phone', $providers) ? false : true; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the validation rules that apply to the request. |
72
|
|
|
* |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function rules() |
76
|
|
|
{ |
77
|
|
|
return $this->isMethod('post') ? [ |
78
|
|
|
'token' => 'required|numeric', |
79
|
|
|
] : []; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.