|
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\Exceptions\DisplayException; |
|
33
|
|
|
use Pterodactyl\Http\Controllers\Controller; |
|
34
|
|
|
use Pterodactyl\Repositories\UserRepository; |
|
35
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException; |
|
36
|
|
|
|
|
37
|
|
|
class UserController extends Controller |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* Controller Constructor. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct() |
|
43
|
|
|
{ |
|
44
|
|
|
// |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
// @TODO: implement nicolaslopezj/searchable to clean up this disaster. |
|
48
|
|
|
public function getIndex(Request $request) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
return view('admin.users.index', [ |
|
51
|
|
|
'users' => User::paginate(25), |
|
52
|
|
|
]); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getNew(Request $request) |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
return view('admin.users.new'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getView(Request $request, $id) |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
return view('admin.users.view', [ |
|
63
|
|
|
'user' => User::with('servers.node')->findOrFail($id), |
|
|
|
|
|
|
64
|
|
|
]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
View Code Duplication |
public function deleteUser(Request $request, $id) |
|
|
|
|
|
|
68
|
|
|
{ |
|
69
|
|
|
try { |
|
70
|
|
|
$repo = new UserRepository; |
|
71
|
|
|
$repo->delete($id); |
|
72
|
|
|
Alert::success('Successfully deleted user from system.')->flash(); |
|
73
|
|
|
|
|
74
|
|
|
return redirect()->route('admin.users'); |
|
75
|
|
|
} catch (DisplayException $ex) { |
|
76
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
77
|
|
|
} catch (\Exception $ex) { |
|
78
|
|
|
Log::error($ex); |
|
79
|
|
|
Alert::danger('An exception was encountered while attempting to delete this user.')->flash(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return redirect()->route('admin.users.view', $id); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function postNew(Request $request) |
|
86
|
|
|
{ |
|
87
|
|
|
try { |
|
88
|
|
|
$user = new UserRepository; |
|
89
|
|
|
$userid = $user->create($request->only([ |
|
90
|
|
|
'email', 'password', 'name_first', |
|
91
|
|
|
'name_last', 'username', 'root_admin', |
|
92
|
|
|
])); |
|
93
|
|
|
Alert::success('Account has been successfully created.')->flash(); |
|
94
|
|
|
|
|
95
|
|
|
return redirect()->route('admin.users.view', $userid); |
|
|
|
|
|
|
96
|
|
|
} catch (DisplayValidationException $ex) { |
|
97
|
|
|
return redirect()->route('admin.users.new')->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
98
|
|
|
} catch (\Exception $ex) { |
|
99
|
|
|
Log::error($ex); |
|
100
|
|
|
Alert::danger('An error occured while attempting to add a new user.')->flash(); |
|
101
|
|
|
|
|
102
|
|
|
return redirect()->route('admin.users.new'); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function updateUser(Request $request, $user) |
|
107
|
|
|
{ |
|
108
|
|
|
try { |
|
109
|
|
|
$repo = new UserRepository; |
|
110
|
|
|
$repo->update($user, $request->only([ |
|
111
|
|
|
'email', 'password', 'name_first', |
|
112
|
|
|
'name_last', 'username', 'root_admin', |
|
113
|
|
|
])); |
|
114
|
|
|
Alert::success('User account was successfully updated.')->flash(); |
|
115
|
|
|
} catch (DisplayValidationException $ex) { |
|
116
|
|
|
return redirect()->route('admin.users.view', $user)->withErrors(json_decode($ex->getMessage())); |
|
117
|
|
|
} catch (\Exception $e) { |
|
118
|
|
|
Log::error($e); |
|
119
|
|
|
Alert::danger('An error occured while attempting to update this user.')->flash(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return redirect()->route('admin.users.view', $user); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function getJson(Request $request) |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
return User::select('email')->get()->pluck('email'); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.