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 Rinvex\Country\Loader; |
19
|
|
|
use Illuminate\Support\Facades\Auth; |
20
|
|
|
use Rinvex\Fort\Contracts\UserRepositoryContract; |
21
|
|
|
use Rinvex\Fort\Http\Requests\Frontend\ProfileUpdate; |
22
|
|
|
use Rinvex\Fort\Http\Controllers\AuthorizedController; |
23
|
|
|
|
24
|
|
|
class UserSettingsController extends AuthorizedController |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* The user repository instance. |
28
|
|
|
* |
29
|
|
|
* @var \Rinvex\Fort\Contracts\UserRepositoryContract |
30
|
|
|
*/ |
31
|
|
|
protected $userRepository; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Create a new profile update controller instance. |
35
|
|
|
* |
36
|
|
|
* @param \Rinvex\Fort\Contracts\UserRepositoryContract $userRepository |
37
|
|
|
* |
38
|
|
|
* @return void |
|
|
|
|
39
|
|
|
*/ |
40
|
|
|
public function __construct(UserRepositoryContract $userRepository) |
41
|
|
|
{ |
42
|
|
|
parent::__construct(); |
43
|
|
|
|
44
|
|
|
$this->userRepository = $userRepository; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Show the account update form. |
49
|
|
|
* |
50
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
51
|
|
|
*/ |
52
|
|
|
public function edit() |
53
|
|
|
{ |
54
|
|
|
$countries = Loader::countries(); |
55
|
|
|
$twoFactor = $this->currentUser()->getTwoFactor(); |
56
|
|
|
|
57
|
|
|
return view('rinvex.fort::frontend.user.settings', compact('twoFactor', 'countries')); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Process the account update form. |
62
|
|
|
* |
63
|
|
|
* @param \Rinvex\Fort\Http\Requests\Frontend\ProfileUpdate $request |
64
|
|
|
* |
65
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
66
|
|
|
*/ |
67
|
|
|
public function update(ProfileUpdate $request) |
68
|
|
|
{ |
69
|
|
|
$currentUser = $this->currentUser(); |
70
|
|
|
$data = $request->except(['_token', 'id']); |
71
|
|
|
$twoFactor = $currentUser->getTwoFactor(); |
72
|
|
|
|
73
|
|
|
if (isset($data['password'])) { |
74
|
|
|
$data['password'] = bcrypt($data['password']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$emailVerification = $data['email'] != $currentUser->email ? [ |
|
|
|
|
78
|
|
|
'email_verified' => false, |
79
|
|
|
'email_verified_at' => null, |
80
|
|
|
] : []; |
81
|
|
|
|
82
|
|
|
$phoneVerification = $data['phone'] != $currentUser->phone ? [ |
|
|
|
|
83
|
|
|
'phone_verified' => false, |
84
|
|
|
'phone_verified_at' => null, |
85
|
|
|
] : []; |
86
|
|
|
|
87
|
|
|
$countryVerification = $data['country'] !== $currentUser->country; |
|
|
|
|
88
|
|
|
|
89
|
|
|
if ($phoneVerification || $countryVerification) { |
|
|
|
|
90
|
|
|
array_set($twoFactor, 'phone.enabled', false); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$this->userRepository->update($request->get('id'), $data + $emailVerification + $phoneVerification + $twoFactor); |
|
|
|
|
94
|
|
|
|
95
|
|
|
return intend([ |
96
|
|
|
'back' => true, |
97
|
|
|
'with' => [ |
98
|
|
|
'rinvex.fort.alert.success' => trans('rinvex.fort::frontend/messages.account.'.(! empty($emailVerification) ? 'reverify' : 'updated')), |
|
|
|
|
99
|
|
|
] + ($twoFactor !== $currentUser->getTwoFactor() ? ['rinvex.fort.alert.warning' => trans('rinvex.fort::frontend/messages.verification.twofactor.phone.auto_disabled')] : []), |
|
|
|
|
100
|
|
|
]); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get current user. |
105
|
|
|
* |
106
|
|
|
* @return \Rinvex\Fort\Contracts\AuthenticatableContract |
107
|
|
|
*/ |
108
|
|
|
protected function currentUser() |
109
|
|
|
{ |
110
|
|
|
return Auth::guard($this->getGuard())->user(); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.