|
2 | 2 |
|
3 | 3 | namespace Pterodactyl\Http\Controllers\API; |
4 | 4 |
|
5 | | -use Gate; |
6 | | -use Log; |
7 | | -use Debugbar; |
8 | | -use Pterodactyl\Models\API; |
9 | | -use Pterodactyl\Models\User; |
10 | | - |
11 | | -use Pterodactyl\Http\Controllers\Controller; |
12 | 5 | use Illuminate\Http\Request; |
13 | 6 |
|
14 | | -class UserController extends Controller |
15 | | -{ |
16 | | - |
17 | | - /** |
18 | | - * Constructor |
19 | | - */ |
20 | | - public function __construct() |
21 | | - { |
22 | | - // |
23 | | - } |
24 | | - |
25 | | - public function getAllUsers(Request $request) |
26 | | - { |
27 | | - |
28 | | - // Policies don't work if the user isn't logged in for whatever reason in Laravel... |
29 | | - if(!API::checkPermission($request->header('X-Authorization'), 'get-users')) { |
30 | | - return API::noPermissionError(); |
31 | | - } |
| 7 | +use Pterodactyl\Transformers\UserTransformer; |
| 8 | +use Pterodactyl\Models; |
32 | 9 |
|
33 | | - return response()->json([ |
34 | | - 'users' => User::all() |
35 | | - ]); |
36 | | - } |
| 10 | +/** |
| 11 | + * @Resource("Users", uri="/users") |
| 12 | + */ |
| 13 | +class UserController extends BaseController |
| 14 | +{ |
37 | 15 |
|
38 | 16 | /** |
39 | | - * Returns JSON response about a user given their ID. |
40 | | - * If fields are provided only those fields are returned. |
| 17 | + * List All Users |
41 | 18 | * |
42 | | - * Does not return protected fields (i.e. password & totp_secret) |
| 19 | + * Lists all users currently on the system. |
43 | 20 | * |
44 | | - * @param Request $request |
45 | | - * @param int $id |
46 | | - * @param string $fields |
47 | | - * @return Response |
| 21 | + * @Get("/{?page}") |
| 22 | + * @Versions({"v1"}) |
| 23 | + * @Parameters({ |
| 24 | + * @Parameter("page", type="integer", description="The page of results to view.", default=1) |
| 25 | + * }) |
| 26 | + * @Response(200) |
48 | 27 | */ |
49 | | - public function getUser(Request $request, $id, $fields = null) |
50 | | - { |
51 | | - |
52 | | - // Policies don't work if the user isn't logged in for whatever reason in Laravel... |
53 | | - if(!API::checkPermission($request->header('X-Authorization'), 'get-users')) { |
54 | | - return API::noPermissionError(); |
55 | | - } |
56 | | - |
57 | | - if (is_null($fields)) { |
58 | | - return response()->json(User::find($id)); |
59 | | - } |
60 | | - |
61 | | - $query = User::where('id', $id); |
62 | | - $explode = explode(',', $fields); |
63 | | - |
64 | | - foreach($explode as &$exploded) { |
65 | | - if(!empty($exploded)) { |
66 | | - $query->addSelect($exploded); |
67 | | - } |
68 | | - } |
69 | | - |
70 | | - try { |
71 | | - return response()->json($query->get()); |
72 | | - } catch (\Exception $e) { |
73 | | - if ($e instanceof \Illuminate\Database\QueryException) { |
74 | | - return response()->json([ |
75 | | - 'error' => 'One of the fields provided in your argument list is invalid.' |
76 | | - ], 500); |
77 | | - } |
78 | | - throw $e; |
79 | | - } |
80 | | - |
| 28 | + public function getUsers(Request $request) { |
| 29 | + $users = Models\User::paginate(15); |
| 30 | + return $this->response->paginator($users, new UserTransformer); |
81 | 31 | } |
82 | 32 |
|
83 | 33 | } |
0 commit comments