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