|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Chuckbe\Chuckcms\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Chuckbe\Chuckcms\Chuck\UserRepository; |
|
6
|
|
|
use Chuckbe\Chuckcms\Mail\UserActivationMail; |
|
7
|
|
|
use Chuckbe\Chuckcms\Models\User; |
|
8
|
|
|
use ChuckSite; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
use Spatie\Permission\Models\Role; |
|
11
|
|
|
use Spatie\Permission\Models\Permission; |
|
12
|
|
|
|
|
13
|
|
|
use Mail; |
|
14
|
|
|
use Illuminate\Http\Request; |
|
15
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
|
16
|
|
|
use Illuminate\Routing\Controller as BaseController; |
|
17
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests; |
|
18
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
|
19
|
|
|
|
|
20
|
|
|
class UserController extends BaseController |
|
21
|
|
|
{ |
|
22
|
|
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; |
|
23
|
|
|
|
|
24
|
|
|
private $user; |
|
25
|
|
|
private $userRepository; |
|
26
|
|
|
/** |
|
27
|
|
|
* Create a new controller instance. |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(User $user, UserRepository $userRepository) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->user = $user; |
|
34
|
|
|
$this->userRepository = $userRepository; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Show the dashboard -> users. |
|
39
|
|
|
* |
|
40
|
|
|
* @return \Illuminate\View\View |
|
41
|
|
|
*/ |
|
42
|
|
|
public function index() |
|
43
|
|
|
{ |
|
44
|
|
|
$users = $this->user->get(); |
|
45
|
|
|
|
|
46
|
|
|
return view('chuckcms::backend.users.index', compact('users')); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function invite(Request $request) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->validate(request(), [//@todo create custom Request class for page validation |
|
52
|
|
|
'name' => 'max:185|required', |
|
53
|
|
|
'email' => 'email|required|unique:users', |
|
54
|
|
|
'role' => 'required|in:user,moderator,administrator,super-admin' |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
|
|
// create the user |
|
58
|
|
|
$user = $this->user->create([ |
|
59
|
|
|
'name' => $request->get('name'), |
|
60
|
|
|
'email' => $request->get('email'), |
|
61
|
|
|
'token' => $this->userRepository->createToken(), |
|
62
|
|
|
'password' => bcrypt($this->userRepository->createToken()) |
|
63
|
|
|
]); |
|
64
|
|
|
// add role |
|
65
|
|
|
$user->assignRole($request->get('role')); |
|
66
|
|
|
|
|
67
|
|
|
//send the email |
|
68
|
|
|
$mailData = []; |
|
69
|
|
|
$mailData['from'] = '[email protected]'; |
|
70
|
|
|
$mailData['from_name'] = 'No Reply | ChuckCMS'; |
|
71
|
|
|
$mailData['to'] = $user->email; |
|
72
|
|
|
$mailData['to_name'] = $user->name; |
|
73
|
|
|
$mailData['token'] = $user->token; |
|
74
|
|
|
$mailData['user'] = \Auth::user(); |
|
75
|
|
|
|
|
76
|
|
|
$settings = ChuckSite::getSettings(); |
|
77
|
|
|
|
|
78
|
|
|
//dd($mailData); |
|
79
|
|
|
|
|
80
|
|
|
Mail::send(new UserActivationMail($mailData, $settings)); |
|
81
|
|
|
|
|
82
|
|
|
//redirect back |
|
83
|
|
|
return redirect()->back()->with('notification', 'Gebruiker uitgenodigd!'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function activateIndex($token) |
|
87
|
|
|
{ |
|
88
|
|
|
// Look up the user |
|
89
|
|
|
$user = $this->user->where('token', $token)->where('active', 0)->first(); |
|
90
|
|
|
|
|
91
|
|
|
if (!$user) { |
|
92
|
|
|
//if the invite doesn't exist do something more graceful than this |
|
93
|
|
|
return redirect()->route('page'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return view('chuckcms::backend.users._accept', compact('user', 'token')); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function activate(Request $request) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->validate(request(), [//@todo create custom Request class for user password validation |
|
102
|
|
|
'password' => 'required|min:8|regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/', |
|
103
|
|
|
'password_again' => 'required|same:password', |
|
104
|
|
|
'_user_token' => 'required', |
|
105
|
|
|
'_user_id' => 'required' |
|
106
|
|
|
]); |
|
107
|
|
|
|
|
108
|
|
|
$token = $request->get('_user_token'); |
|
109
|
|
|
$user_id = $request->get('_user_id'); |
|
110
|
|
|
|
|
111
|
|
|
// Look up the user |
|
112
|
|
|
if (!$user = $this->user->where('token', $token)->where('id', $user_id)->where('active', 0)->first()) { |
|
|
|
|
|
|
113
|
|
|
//if the user doesn't exist do something more graceful than this |
|
114
|
|
|
return redirect()->route('page'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$this->user->where('token', $token)->where('id', $user_id)->where('active', 0)->update([ |
|
118
|
|
|
'active' => 1, |
|
119
|
|
|
'password' => bcrypt($request->get('password')) |
|
120
|
|
|
]); |
|
121
|
|
|
|
|
122
|
|
|
return redirect()->route('login'); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Show the edit user page. |
|
127
|
|
|
* |
|
128
|
|
|
* @return \Illuminate\View\View |
|
129
|
|
|
*/ |
|
130
|
|
|
public function edit(User $user) |
|
131
|
|
|
{ |
|
132
|
|
|
$roles = Role::all(); |
|
133
|
|
|
$permissions = Permission::all(); |
|
134
|
|
|
return view('chuckcms::backend.users.edit', compact('user', 'roles', 'permissions')); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function resendInvitation(Request $request) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->validate(request(), [ |
|
140
|
|
|
'user_id' => 'required', |
|
141
|
|
|
]); |
|
142
|
|
|
|
|
143
|
|
|
// get the user |
|
144
|
|
|
$user = $this->user->find($request->user_id); |
|
145
|
|
|
|
|
146
|
|
|
$user->update([ |
|
147
|
|
|
'active' => 0, |
|
148
|
|
|
'token' => $this->userRepository->createToken() |
|
149
|
|
|
]); |
|
150
|
|
|
|
|
151
|
|
|
//send the email |
|
152
|
|
|
$mailData = []; |
|
153
|
|
|
$mailData['from'] = '[email protected]'; |
|
154
|
|
|
$mailData['from_name'] = 'No Reply | ChuckCMS'; |
|
155
|
|
|
$mailData['to'] = $user->email; |
|
156
|
|
|
$mailData['to_name'] = $user->name; |
|
157
|
|
|
$mailData['token'] = $user->token; |
|
158
|
|
|
$mailData['user'] = \Auth::user(); |
|
159
|
|
|
|
|
160
|
|
|
$settings = ChuckSite::getSettings(); |
|
161
|
|
|
|
|
162
|
|
|
//dd($mailData); |
|
163
|
|
|
|
|
164
|
|
|
Mail::send(new UserActivationMail($mailData, $settings)); |
|
165
|
|
|
|
|
166
|
|
|
//redirect back |
|
167
|
|
|
return 'success'; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function save(Request $request) |
|
171
|
|
|
{ |
|
172
|
|
|
$this->validate(request(), [//@todo create custom Request class for page validation |
|
173
|
|
|
'name' => 'max:185|required', |
|
174
|
|
|
'email' => 'email|required', |
|
175
|
|
|
'role' => 'required|in:user,moderator,administrator,super-admin' |
|
176
|
|
|
]); |
|
177
|
|
|
|
|
178
|
|
|
// update the user |
|
179
|
|
|
$user = $this->user->create([// TODO CHANGE TO UPDATE METHOD |
|
180
|
|
|
'name' => $request->get('name'), |
|
181
|
|
|
'email' => $request->get('email'), |
|
182
|
|
|
'token' => $this->userRepository->createToken(), |
|
183
|
|
|
'password' => bcrypt($this->userRepository->createToken()) |
|
184
|
|
|
]); |
|
185
|
|
|
// add role |
|
186
|
|
|
$user->assignRole($request->get('role')); |
|
187
|
|
|
|
|
188
|
|
|
//send the email |
|
189
|
|
|
$mailData = []; |
|
190
|
|
|
$mailData['from'] = '[email protected]'; |
|
191
|
|
|
$mailData['from_name'] = 'No Reply | ChuckCMS'; |
|
192
|
|
|
$mailData['to'] = $user->email; |
|
193
|
|
|
$mailData['to_name'] = $user->name; |
|
194
|
|
|
$mailData['token'] = $user->token; |
|
195
|
|
|
$mailData['user'] = \Auth::user(); |
|
196
|
|
|
|
|
197
|
|
|
$settings = ChuckSite::getSettings(); |
|
198
|
|
|
|
|
199
|
|
|
//dd($mailData); |
|
200
|
|
|
|
|
201
|
|
|
Mail::send(new UserActivationMail($mailData, $settings)); |
|
202
|
|
|
|
|
203
|
|
|
//redirect back |
|
204
|
|
|
return redirect()->back()->with('notification', 'Gebruiker uitgenodigd!'); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Delete the user. |
|
209
|
|
|
* |
|
210
|
|
|
* @return string $status |
|
211
|
|
|
*/ |
|
212
|
|
|
public function delete(Request $request) |
|
213
|
|
|
{ |
|
214
|
|
|
$this->validate(request(), [ |
|
215
|
|
|
'user_id' => 'required', |
|
216
|
|
|
]); |
|
217
|
|
|
|
|
218
|
|
|
$status = $this->user->deleteById($request->get('user_id')); |
|
219
|
|
|
return $status; |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|
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