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
|
|
|
|
11
|
|
|
class AccountController extends Controller |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @inheritDoc |
15
|
|
|
*/ |
16
|
|
|
public function __construct() |
17
|
|
|
{ |
18
|
|
|
parent::__construct(); |
19
|
|
|
|
20
|
|
|
$this->module = ucmodule('user'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Display user account page |
25
|
|
|
* |
26
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
public function index(?Domain $domain, Module $module) |
29
|
|
|
{ |
30
|
|
|
$this->preProcess($domain, $module, request()); |
|
|
|
|
31
|
|
|
|
32
|
|
|
$this->viewName = 'account.main'; |
33
|
|
|
|
34
|
|
|
$user = auth()->user(); |
|
|
|
|
35
|
|
|
|
36
|
|
|
return $this->autoView(compact('user')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Update user profile |
41
|
|
|
* |
42
|
|
|
* @return \Illuminate\Http\Response |
43
|
|
|
*/ |
44
|
|
|
public function updateProfile(?Domain $domain, Module $module) |
45
|
|
|
{ |
46
|
|
|
$this->preProcess($domain, $module, request()); |
|
|
|
|
47
|
|
|
|
48
|
|
|
$user = auth()->user(); |
|
|
|
|
49
|
|
|
|
50
|
|
|
$rules = Field::where('module_id', ucmodule('user')->id)->pluck('data', 'name')->map(function($item, $key) use($user) { |
|
|
|
|
51
|
|
|
return isset($item->rules) ? explode('|', str_replace('%id%', $user->id, $item->rules)) : ''; |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
$validator = Validator::make(request()->all(), [ |
55
|
|
|
'username' => $rules['username'], |
56
|
|
|
'name' => $rules['name'], |
57
|
|
|
'email' => $rules['email'], |
58
|
|
|
]); |
59
|
|
|
|
60
|
|
|
if ($validator->fails()) { |
61
|
|
|
ucnotify(uctrans('notification.form.not_valid', $module), 'error'); |
|
|
|
|
62
|
|
|
|
63
|
|
|
return redirect(ucroute('uccello.user.account', $domain)) |
|
|
|
|
64
|
|
|
->withErrors($validator) |
65
|
|
|
->withInput() |
66
|
|
|
->with('form_name', 'profile'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$user->username = request('username'); |
70
|
|
|
$user->name = request('name'); |
71
|
|
|
$user->email = request('email'); |
72
|
|
|
$user->save(); |
73
|
|
|
|
74
|
|
|
ucnotify(uctrans('success.profile_updated', ucmodule('user')), 'success'); |
75
|
|
|
|
76
|
|
|
return redirect(ucroute('uccello.user.account', $domain)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Update user avatar |
81
|
|
|
* |
82
|
|
|
* @return \Illuminate\Http\Response |
83
|
|
|
*/ |
84
|
|
|
public function updateAvatar(?Domain $domain, Module $module) |
85
|
|
|
{ |
86
|
|
|
$this->preProcess($domain, $module, request()); |
|
|
|
|
87
|
|
|
|
88
|
|
|
$user = auth()->user(); |
|
|
|
|
89
|
|
|
|
90
|
|
|
$avatarType = request('avatar_type'); |
91
|
|
|
$avatar = [ 'type' => $avatarType ]; |
92
|
|
|
|
93
|
|
|
if (request('avatar')) { |
94
|
|
|
$image = str_replace('data:image/png;base64,', '', request('avatar')); |
95
|
|
|
$image = str_replace(' ', '+', $image); |
96
|
|
|
$imageName = 'user-' . $user->id . '.png'; |
97
|
|
|
$path = storage_path('app/public/avatar/'); |
|
|
|
|
98
|
|
|
$filepath = $path . $imageName; |
99
|
|
|
|
100
|
|
|
if(!\File::isDirectory($path)){ |
101
|
|
|
\File::makeDirectory($path, 0777, true, true); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
\File::put($filepath, base64_decode($image)); |
105
|
|
|
|
106
|
|
|
$avatar[ 'path' ] = "/storage/avatar/$imageName"; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$user->avatar = $avatar; |
110
|
|
|
$user->save(); |
111
|
|
|
|
112
|
|
|
ucnotify(uctrans('success.avatar_updated', ucmodule('user')), 'success'); |
|
|
|
|
113
|
|
|
|
114
|
|
|
return redirect(ucroute('uccello.user.account', $domain)) |
|
|
|
|
115
|
|
|
->with('form_name', 'avatar'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Update user password |
120
|
|
|
* |
121
|
|
|
* @return \Illuminate\Http\Response |
122
|
|
|
*/ |
123
|
|
|
public function updatePassword(?Domain $domain, Module $module) |
124
|
|
|
{ |
125
|
|
|
$this->preProcess($domain, $module, request()); |
|
|
|
|
126
|
|
|
|
127
|
|
|
$user = auth()->user(); |
|
|
|
|
128
|
|
|
|
129
|
|
|
$field = Field::where('module_id', ucmodule('user')->id)->where('name', 'password')->first(); |
130
|
|
|
$password_rules = isset($field->data->rules) ? explode('|', $field->data->rules) : ''; |
131
|
|
|
$password_rules[] = 'confirmed'; |
132
|
|
|
|
133
|
|
|
$validator = Validator::make(request()->all(), [ |
134
|
|
|
'current_password' => function($attribute, $value, $fail) use ($user) { |
135
|
|
|
if (!\Hash::check($value, $user->password)) { |
136
|
|
|
$fail(uctrans('error.current_password', ucmodule('user'))); |
137
|
|
|
} |
138
|
|
|
}, |
139
|
|
|
'password' => $password_rules, |
140
|
|
|
]); |
141
|
|
|
|
142
|
|
|
if ($validator->fails()) { |
143
|
|
|
ucnotify(uctrans('notification.form.not_valid', $module), 'error'); |
|
|
|
|
144
|
|
|
|
145
|
|
|
return redirect(ucroute('uccello.user.account', $domain)) |
|
|
|
|
146
|
|
|
->withErrors($validator) |
147
|
|
|
->withInput() |
148
|
|
|
->with('form_name', 'password'); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
$user->password = \Hash::make(request('password')); |
152
|
|
|
$user->save(); |
153
|
|
|
|
154
|
|
|
ucnotify(uctrans('success.password_updated', ucmodule('user')), 'success'); |
155
|
|
|
|
156
|
|
|
return redirect(ucroute('uccello.user.account', $domain)); |
157
|
|
|
} |
158
|
|
|
} |
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