|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cortex\Auth\Http\Requests\Adminarea; |
|
6
|
|
|
|
|
7
|
|
|
use Rinvex\Support\Traits\Escaper; |
|
8
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
|
9
|
|
|
|
|
10
|
|
|
class AccountSettingsRequest extends FormRequest |
|
11
|
|
|
{ |
|
12
|
|
|
use Escaper; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Determine if the user is authorized to make this request. |
|
16
|
|
|
* |
|
17
|
|
|
* @return bool |
|
18
|
|
|
*/ |
|
19
|
|
|
public function authorize(): bool |
|
20
|
|
|
{ |
|
21
|
|
|
return true; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Prepare the data for validation. |
|
26
|
|
|
* |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function prepareForValidation(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$data = $this->all(); |
|
32
|
|
|
|
|
33
|
|
|
$country = $data['country_code'] ?? null; |
|
34
|
|
|
$email = $data['email'] ?? null; |
|
35
|
|
|
$phone = $data['phone'] ?? null; |
|
36
|
|
|
$user = $this->user($this->route('guard')); |
|
37
|
|
|
$twoFactor = $user->getTwoFactor(); |
|
38
|
|
|
|
|
39
|
|
|
if ($email !== $user->email) { |
|
40
|
|
|
$data['email_verified'] = false; |
|
41
|
|
|
$data['email_verified_at'] = null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if ($phone !== $user->phone) { |
|
45
|
|
|
$data['phone_verified'] = false; |
|
46
|
|
|
$data['phone_verified_at'] = null; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if ($twoFactor && (isset($data['phone_verified']) || $country !== $user->country_code)) { |
|
50
|
|
|
array_set($twoFactor, 'phone.enabled', false); |
|
51
|
|
|
$data['two_factor'] = $twoFactor; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$this->replace($data); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Configure the validator instance. |
|
59
|
|
|
* |
|
60
|
|
|
* @param \Illuminate\Validation\Validator $validator |
|
61
|
|
|
* |
|
62
|
|
|
* @return void |
|
63
|
|
|
*/ |
|
64
|
|
|
public function withValidator($validator): void |
|
65
|
|
|
{ |
|
66
|
|
|
// Sanitize input data before submission |
|
67
|
|
|
$this->replace($this->escape($this->all())); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get the validation rules that apply to the request. |
|
72
|
|
|
* |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
public function rules(): array |
|
76
|
|
|
{ |
|
77
|
|
|
$user = $this->user($this->route('guard')); |
|
78
|
|
|
$user->updateRulesUniques(); |
|
79
|
|
|
|
|
80
|
|
|
return $user->getRules(); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|