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 save(Request $request) |
138
|
|
|
{ |
139
|
|
|
$this->validate(request(), [//@todo create custom Request class for page validation |
140
|
|
|
'name' => 'max:185|required', |
141
|
|
|
'email' => 'email|required', |
142
|
|
|
'role' => 'required|in:user,moderator,administrator,super-admin' |
143
|
|
|
]); |
144
|
|
|
|
145
|
|
|
// update the user |
146
|
|
|
$user = $this->user->create([// TODO CHANGE TO UPDATE METHOD |
147
|
|
|
'name' => $request->get('name'), |
148
|
|
|
'email' => $request->get('email'), |
149
|
|
|
'token' => $this->userRepository->createToken(), |
150
|
|
|
'password' => bcrypt($this->userRepository->createToken()) |
151
|
|
|
]); |
152
|
|
|
// add role |
153
|
|
|
$user->assignRole($request->get('role')); |
154
|
|
|
|
155
|
|
|
//send the email |
156
|
|
|
$mailData = []; |
157
|
|
|
$mailData['from'] = '[email protected]'; |
158
|
|
|
$mailData['from_name'] = 'No Reply | ChuckCMS'; |
159
|
|
|
$mailData['to'] = $user->email; |
160
|
|
|
$mailData['to_name'] = $user->name; |
161
|
|
|
$mailData['token'] = $user->token; |
162
|
|
|
$mailData['user'] = \Auth::user(); |
163
|
|
|
|
164
|
|
|
$settings = ChuckSite::getSettings(); |
165
|
|
|
|
166
|
|
|
//dd($mailData); |
167
|
|
|
|
168
|
|
|
Mail::send(new UserActivationMail($mailData, $settings)); |
169
|
|
|
|
170
|
|
|
//redirect back |
171
|
|
|
return redirect()->back()->with('notification', 'Gebruiker uitgenodigd!'); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Delete the user. |
176
|
|
|
* |
177
|
|
|
* @return string $status |
178
|
|
|
*/ |
179
|
|
|
public function delete(Request $request) |
180
|
|
|
{ |
181
|
|
|
$this->validate(request(), [ |
182
|
|
|
'user_id' => 'required', |
183
|
|
|
]); |
184
|
|
|
|
185
|
|
|
$status = $this->user->deleteById($request->get('user_id')); |
186
|
|
|
return $status; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
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