1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Uccello\Core\Http\Controllers\User; |
4
|
|
|
|
5
|
|
|
use Uccello\Core\Http\Controllers\Core\Controller; |
6
|
|
|
use Uccello\Core\Models\Domain; |
7
|
|
|
use Uccello\Core\Models\Module; |
8
|
|
|
use Uccello\Core\Models\Field; |
9
|
|
|
use Illuminate\Support\Facades\Validator; |
|
|
|
|
10
|
|
|
use Uccello\Core\Models\UserSettings; |
11
|
|
|
|
12
|
|
|
class AccountController extends Controller |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @inheritDoc |
16
|
|
|
*/ |
17
|
|
|
public function __construct() |
18
|
|
|
{ |
19
|
|
|
parent::__construct(); |
20
|
|
|
|
21
|
|
|
$this->module = ucmodule('user'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Display user account page |
26
|
|
|
* |
27
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
28
|
|
|
*/ |
29
|
|
|
public function index(?Domain $domain, Module $module) |
30
|
|
|
{ |
31
|
|
|
$this->preProcess($domain, $module, request()); |
|
|
|
|
32
|
|
|
|
33
|
|
|
$this->viewName = 'account.main'; |
34
|
|
|
|
35
|
|
|
$user = auth()->user(); |
|
|
|
|
36
|
|
|
|
37
|
|
|
return $this->autoView(compact('user')); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Update user profile |
42
|
|
|
* |
43
|
|
|
* @return \Illuminate\Http\Response |
44
|
|
|
*/ |
45
|
|
|
public function updateProfile(?Domain $domain, Module $module) |
46
|
|
|
{ |
47
|
|
|
$this->preProcess($domain, $module, request()); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$user = auth()->user(); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$rules = Field::where('module_id', ucmodule('user')->id)->pluck('data', 'name')->map(function($item, $key) use($user) { |
|
|
|
|
52
|
|
|
return isset($item->rules) ? explode('|', str_replace('%id%', $user->id, $item->rules)) : ''; |
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
$validator = Validator::make(request()->all(), [ |
56
|
|
|
'username' => $rules['username'], |
57
|
|
|
'name' => $rules['name'], |
58
|
|
|
'email' => $rules['email'], |
59
|
|
|
]); |
60
|
|
|
|
61
|
|
|
if ($validator->fails()) { |
62
|
|
|
ucnotify(uctrans('notification.form.not_valid', $module), 'error'); |
|
|
|
|
63
|
|
|
|
64
|
|
|
return redirect(ucroute('uccello.user.account', $domain)) |
|
|
|
|
65
|
|
|
->withErrors($validator) |
66
|
|
|
->withInput() |
67
|
|
|
->with('form_name', 'profile'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$user->username = request('username'); |
71
|
|
|
$user->name = request('name'); |
72
|
|
|
$user->email = request('email'); |
73
|
|
|
$user->save(); |
74
|
|
|
|
75
|
|
|
ucnotify(uctrans('success.profile_updated', ucmodule('user')), 'success'); |
76
|
|
|
|
77
|
|
|
return redirect(ucroute('uccello.user.account', $domain)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Update user avatar |
82
|
|
|
* |
83
|
|
|
* @return \Illuminate\Http\Response |
84
|
|
|
*/ |
85
|
|
|
public function updateAvatar(?Domain $domain, Module $module) |
86
|
|
|
{ |
87
|
|
|
$this->preProcess($domain, $module, request()); |
|
|
|
|
88
|
|
|
|
89
|
|
|
$user = auth()->user(); |
|
|
|
|
90
|
|
|
|
91
|
|
|
$avatarType = request('avatar_type'); |
92
|
|
|
$avatar = [ 'type' => $avatarType ]; |
93
|
|
|
|
94
|
|
|
if (request('avatar')) { |
95
|
|
|
$image = str_replace('data:image/png;base64,', '', request('avatar')); |
96
|
|
|
$image = str_replace(' ', '+', $image); |
97
|
|
|
$imageName = 'user-' . $user->id . '.png'; |
98
|
|
|
$path = storage_path('app/public/avatar/'); |
|
|
|
|
99
|
|
|
$filepath = $path . $imageName; |
100
|
|
|
|
101
|
|
|
if(!\File::isDirectory($path)){ |
102
|
|
|
\File::makeDirectory($path, 0777, true, true); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
\File::put($filepath, base64_decode($image)); |
106
|
|
|
|
107
|
|
|
$avatar[ 'path' ] = "/storage/avatar/$imageName"; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$user->avatar = $avatar; |
111
|
|
|
$user->save(); |
112
|
|
|
|
113
|
|
|
ucnotify(uctrans('success.avatar_updated', ucmodule('user')), 'success'); |
|
|
|
|
114
|
|
|
|
115
|
|
|
return redirect(ucroute('uccello.user.account', $domain)) |
|
|
|
|
116
|
|
|
->with('form_name', 'avatar'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Update user password |
121
|
|
|
* |
122
|
|
|
* @return \Illuminate\Http\Response |
123
|
|
|
*/ |
124
|
|
|
public function updatePassword(?Domain $domain, Module $module) |
125
|
|
|
{ |
126
|
|
|
$this->preProcess($domain, $module, request()); |
|
|
|
|
127
|
|
|
|
128
|
|
|
$user = auth()->user(); |
|
|
|
|
129
|
|
|
|
130
|
|
|
$field = Field::where('module_id', ucmodule('user')->id)->where('name', 'password')->first(); |
131
|
|
|
$password_rules = isset($field->data->rules) ? explode('|', $field->data->rules) : ''; |
132
|
|
|
$password_rules[] = 'confirmed'; |
133
|
|
|
|
134
|
|
|
$validator = Validator::make(request()->all(), [ |
135
|
|
|
'current_password' => function($attribute, $value, $fail) use ($user) { |
136
|
|
|
if (!\Hash::check($value, $user->password)) { |
137
|
|
|
$fail(uctrans('error.current_password', ucmodule('user'))); |
138
|
|
|
} |
139
|
|
|
}, |
140
|
|
|
'password' => $password_rules, |
141
|
|
|
]); |
142
|
|
|
|
143
|
|
|
if ($validator->fails()) { |
144
|
|
|
ucnotify(uctrans('notification.form.not_valid', $module), 'error'); |
|
|
|
|
145
|
|
|
|
146
|
|
|
return redirect(ucroute('uccello.user.account', $domain)) |
|
|
|
|
147
|
|
|
->withErrors($validator) |
148
|
|
|
->withInput() |
149
|
|
|
->with('form_name', 'password'); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$user->password = \Hash::make(request('password')); |
153
|
|
|
$user->save(); |
154
|
|
|
|
155
|
|
|
ucnotify(uctrans('success.password_updated', ucmodule('user')), 'success'); |
156
|
|
|
|
157
|
|
|
return redirect(ucroute('uccello.user.account', $domain)); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Update user settings |
162
|
|
|
* |
163
|
|
|
* @return \Illuminate\Http\Response |
164
|
|
|
*/ |
165
|
|
|
public function updateSettings(?Domain $domain, Module $module) |
166
|
|
|
{ |
167
|
|
|
$this->preProcess($domain, $module, request()); |
|
|
|
|
168
|
|
|
|
169
|
|
|
$userSettings = UserSettings::firstOrNew([ |
170
|
|
|
'user_id' => auth()->id() |
|
|
|
|
171
|
|
|
]); |
172
|
|
|
|
173
|
|
|
$data = $userSettings->data ?? new \stdClass; |
174
|
|
|
|
175
|
|
|
foreach ((array) request('settings') as $key => $value) { |
176
|
|
|
if ($value === 'true') { |
177
|
|
|
$value = true; |
178
|
|
|
} elseif ($value === 'false') { |
179
|
|
|
$value = false; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$data->{$key} = $value; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
$userSettings->data = $data; |
186
|
|
|
$userSettings->save(); |
187
|
|
|
|
188
|
|
|
return response()->json($userSettings->data); |
|
|
|
|
189
|
|
|
} |
190
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths