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\Http\Request; |
19
|
|
|
use Rinvex\Fort\Contracts\UserRepositoryContract; |
20
|
|
|
use Rinvex\Fort\Http\Controllers\AuthenticatedController; |
21
|
|
|
use Rinvex\Fort\Http\Requests\Frontend\UserSettingsUpdateRequest; |
22
|
|
|
|
23
|
|
|
class UserSettingsController extends AuthenticatedController |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* The user repository instance. |
27
|
|
|
* |
28
|
|
|
* @var \Rinvex\Fort\Contracts\UserRepositoryContract |
29
|
|
|
*/ |
30
|
|
|
protected $userRepository; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Create a new profile update controller instance. |
34
|
|
|
* |
35
|
|
|
* @param \Rinvex\Fort\Contracts\UserRepositoryContract $userRepository |
36
|
|
|
*/ |
37
|
|
|
public function __construct(UserRepositoryContract $userRepository) |
38
|
|
|
{ |
39
|
|
|
parent::__construct(); |
40
|
|
|
|
41
|
|
|
$this->userRepository = $userRepository; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Show the account update form. |
46
|
|
|
* |
47
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
48
|
|
|
*/ |
49
|
|
|
public function edit(Request $request) |
50
|
|
|
{ |
51
|
|
|
$countries = array_map(function ($country) { |
52
|
|
|
return $country->getName(); |
53
|
|
|
}, countries()); |
54
|
|
|
$twoFactor = $request->user($this->getGuard())->getTwoFactor(); |
55
|
|
|
|
56
|
|
|
return view('rinvex/fort::frontend/user.settings', compact('twoFactor', 'countries')); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Process the account update form. |
61
|
|
|
* |
62
|
|
|
* @param \Rinvex\Fort\Http\Requests\Frontend\UserSettingsUpdateRequest $request |
63
|
|
|
* |
64
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
65
|
|
|
*/ |
66
|
|
|
public function update(UserSettingsUpdateRequest $request) |
67
|
|
|
{ |
68
|
|
|
$currentUser = $request->user($this->getGuard()); |
69
|
|
|
$data = $request->except(['_token', 'id']); |
70
|
|
|
$twoFactor = $currentUser->getTwoFactor(); |
71
|
|
|
|
72
|
|
|
$emailVerification = $data['email'] != $currentUser->email ? [ |
73
|
|
|
'email_verified' => false, |
74
|
|
|
'email_verified_at' => null, |
75
|
|
|
] : []; |
76
|
|
|
|
77
|
|
|
$phoneVerification = $data['phone'] != $currentUser->phone ? [ |
78
|
|
|
'phone_verified' => false, |
79
|
|
|
'phone_verified_at' => null, |
80
|
|
|
] : []; |
81
|
|
|
|
82
|
|
|
$countryVerification = $data['country'] !== $currentUser->country; |
83
|
|
|
|
84
|
|
|
if ($phoneVerification || $countryVerification) { |
|
|
|
|
85
|
|
|
array_set($twoFactor, 'phone.enabled', false); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$this->userRepository->update($request->get('id'), $data + $emailVerification + $phoneVerification + $twoFactor); |
|
|
|
|
89
|
|
|
|
90
|
|
|
return intend([ |
91
|
|
|
'back' => true, |
92
|
|
|
'with' => [ |
93
|
|
|
'rinvex.fort.alert.success' => trans('rinvex/fort::frontend/messages.account.'.(! empty($emailVerification) ? 'reverify' : 'updated')), |
|
|
|
|
94
|
|
|
] + ($twoFactor !== $currentUser->getTwoFactor() ? ['rinvex.fort.alert.warning' => trans('rinvex/fort::frontend/messages.verification.twofactor.phone.auto_disabled')] : []), |
|
|
|
|
95
|
|
|
]); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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.