1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Pterodactyl - Panel |
4
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <[email protected]> |
5
|
|
|
* Some Modifications (c) 2015 Dylan Seidt <[email protected]>. |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
9
|
|
|
* in the Software without restriction, including without limitation the rights |
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
12
|
|
|
* furnished to do so, subject to the following conditions: |
13
|
|
|
* |
14
|
|
|
* The above copyright notice and this permission notice shall be included in all |
15
|
|
|
* copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23
|
|
|
* SOFTWARE. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace Pterodactyl\Http\Controllers\Admin; |
27
|
|
|
|
28
|
|
|
use Log; |
29
|
|
|
use Alert; |
30
|
|
|
use Illuminate\Http\Request; |
31
|
|
|
use Pterodactyl\Models\User; |
32
|
|
|
use Pterodactyl\Models\Server; |
33
|
|
|
use Pterodactyl\Exceptions\DisplayException; |
34
|
|
|
use Pterodactyl\Http\Controllers\Controller; |
35
|
|
|
use Pterodactyl\Repositories\UserRepository; |
36
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException; |
37
|
|
|
|
38
|
|
|
class UserController extends Controller |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* Controller Constructor. |
42
|
|
|
*/ |
43
|
|
|
public function __construct() |
44
|
|
|
{ |
45
|
|
|
// |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// @TODO: implement nicolaslopezj/searchable to clean up this disaster. |
49
|
|
|
public function getIndex(Request $request) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
return view('admin.users.index', [ |
52
|
|
|
'users' => User::paginate(25), |
53
|
|
|
]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getNew(Request $request) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
return view('admin.users.new'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getView(Request $request, $id) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
return view('admin.users.view', [ |
64
|
|
|
'user' => User::with('servers.node')->findOrFail($id), |
|
|
|
|
65
|
|
|
]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
View Code Duplication |
public function deleteUser(Request $request, $id) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
try { |
71
|
|
|
$repo = new UserRepository; |
72
|
|
|
$repo->delete($id); |
73
|
|
|
Alert::success('Successfully deleted user from system.')->flash(); |
74
|
|
|
|
75
|
|
|
return redirect()->route('admin.users'); |
76
|
|
|
} catch (DisplayException $ex) { |
77
|
|
|
Alert::danger($ex->getMessage())->flash(); |
78
|
|
|
} catch (\Exception $ex) { |
79
|
|
|
Log::error($ex); |
80
|
|
|
Alert::danger('An exception was encountered while attempting to delete this user.')->flash(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return redirect()->route('admin.users.view', $id); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function postNew(Request $request) |
87
|
|
|
{ |
88
|
|
|
try { |
89
|
|
|
$user = new UserRepository; |
90
|
|
|
$userid = $user->create($request->only([ |
91
|
|
|
'email', |
92
|
|
|
'password', |
93
|
|
|
'name_first', |
94
|
|
|
'name_last', |
95
|
|
|
'username', |
96
|
|
|
'root_admin', |
97
|
|
|
])); |
98
|
|
|
Alert::success('Account has been successfully created.')->flash(); |
99
|
|
|
|
100
|
|
|
return redirect()->route('admin.users.view', $userid); |
|
|
|
|
101
|
|
|
} catch (DisplayValidationException $ex) { |
102
|
|
|
return redirect()->route('admin.users.new')->withErrors(json_decode($ex->getMessage()))->withInput(); |
103
|
|
|
} catch (\Exception $ex) { |
104
|
|
|
Log::error($ex); |
105
|
|
|
Alert::danger('An error occured while attempting to add a new user.')->flash(); |
106
|
|
|
|
107
|
|
|
return redirect()->route('admin.users.new'); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function updateUser(Request $request, $user) |
112
|
|
|
{ |
113
|
|
|
try { |
114
|
|
|
$repo = new UserRepository; |
115
|
|
|
$repo->update($user, $request->only([ |
116
|
|
|
'email', |
117
|
|
|
'password', |
118
|
|
|
'name_first', |
119
|
|
|
'name_last', |
120
|
|
|
'username', |
121
|
|
|
'root_admin', |
122
|
|
|
])); |
123
|
|
|
Alert::success('User account was successfully updated.')->flash(); |
124
|
|
|
} catch (DisplayValidationException $ex) { |
125
|
|
|
return redirect()->route('admin.users.view', $user)->withErrors(json_decode($ex->getMessage())); |
126
|
|
|
} catch (\Exception $e) { |
127
|
|
|
Log::error($e); |
128
|
|
|
Alert::danger('An error occured while attempting to update this user.')->flash(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return redirect()->route('admin.users.view', $user); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function getJson(Request $request) |
|
|
|
|
135
|
|
|
{ |
136
|
|
|
return User::select('email')->get()->pluck('email'); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.