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