From cede747442a010f6bd25e50d6d6d376235df11d2 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 17 Jun 2017 17:36:39 -0500 Subject: [PATCH] Cleanup user and location controllers. --- .../Controllers/Admin/LocationController.php | 23 ++++++------ app/Http/Controllers/Admin/UserController.php | 36 ++++++++++++------- config/pterodactyl.php | 3 ++ 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/app/Http/Controllers/Admin/LocationController.php b/app/Http/Controllers/Admin/LocationController.php index 8325405f6..1dd3bee2e 100644 --- a/app/Http/Controllers/Admin/LocationController.php +++ b/app/Http/Controllers/Admin/LocationController.php @@ -41,7 +41,7 @@ class LocationController extends Controller /** * @var \Pterodactyl\Models\Location */ - protected $location; + protected $locationModel; /** * @var \Pterodactyl\Services\LocationService @@ -52,13 +52,16 @@ class LocationController extends Controller * LocationController constructor. * * @param \Prologue\Alerts\AlertsMessageBag $alert - * @param \Pterodactyl\Models\Location $location - * @param \Pterodactyl\Services\LocationService $service + * @param \Pterodactyl\Models\Location $locationModel + * @param \Pterodactyl\Services\LocationService $service */ - public function __construct(AlertsMessageBag $alert, Location $location, LocationService $service) - { + public function __construct( + AlertsMessageBag $alert, + Location $locationModel, + LocationService $service + ) { $this->alert = $alert; - $this->location = $location; + $this->locationModel = $locationModel; $this->service = $service; } @@ -70,7 +73,7 @@ class LocationController extends Controller public function index() { return view('admin.locations.index', [ - 'locations' => $this->location->withCount('nodes', 'servers')->get(), + 'locations' => $this->locationModel->withCount('nodes', 'servers')->get(), ]); } @@ -120,7 +123,7 @@ class LocationController extends Controller return $this->delete($location); } - $this->service->update($location, $request->normalize()); + $this->service->update($location->id, $request->normalize()); $this->alert->success('Location was updated successfully.')->flash(); return redirect()->route('admin.locations.view', $location->id); @@ -129,7 +132,7 @@ class LocationController extends Controller /** * Delete a location from the system. * - * @param \Pterodactyl\Models\Location $location + * @param \Pterodactyl\Models\Location $location * @return \Illuminate\Http\RedirectResponse * * @throws \Exception @@ -138,7 +141,7 @@ class LocationController extends Controller public function delete(Location $location) { try { - $this->service->delete($location); + $this->service->delete($location->id); return redirect()->route('admin.locations'); } catch (DisplayException $ex) { diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 1f1bbd56c..2e9a25415 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -1,8 +1,7 @@ - * Some Modifications (c) 2015 Dylan Seidt . + * Copyright (c) 2015 - 2017 Dane Everitt . * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,32 +24,43 @@ namespace Pterodactyl\Http\Controllers\Admin; -use Alert; use Illuminate\Http\Request; -use Prologue\Alerts\AlertsMessageBag; -use Pterodactyl\Exceptions\DisplayException; -use Pterodactyl\Http\Requests\Admin\UserFormRequest; use Pterodactyl\Models\User; -use Pterodactyl\Http\Controllers\Controller; +use Prologue\Alerts\AlertsMessageBag; use Pterodactyl\Services\UserService; +use Pterodactyl\Exceptions\DisplayException; +use Pterodactyl\Http\Controllers\Controller; +use Pterodactyl\Http\Requests\Admin\UserFormRequest; class UserController extends Controller { + /** + * @var \Prologue\Alerts\AlertsMessageBag + */ + protected $alert; + /** * @var \Pterodactyl\Services\UserService */ protected $service; + /** + * @var \Pterodactyl\Models\User + */ + protected $userModel; + /** * UserController constructor. * * @param \Prologue\Alerts\AlertsMessageBag $alert * @param \Pterodactyl\Services\UserService $service + * @param \Pterodactyl\Models\User $userModel */ - public function __construct(AlertsMessageBag $alert, UserService $service) + public function __construct(AlertsMessageBag $alert, UserService $service, User $userModel) { $this->alert = $alert; $this->service = $service; + $this->userModel = $userModel; } /** @@ -61,14 +71,14 @@ class UserController extends Controller */ public function index(Request $request) { - $users = User::withCount('servers', 'subuserOf'); + $users = $this->userModel->withCount('servers', 'subuserOf'); if (! is_null($request->input('query'))) { $users->search($request->input('query')); } return view('admin.users.index', [ - 'users' => $users->paginate(25), + 'users' => $users->paginate(config('pterodactyl.paginate.admin.users')), ]); } @@ -106,7 +116,7 @@ class UserController extends Controller public function delete(User $user) { try { - $this->service->delete($user); + $this->service->delete($user->id); return redirect()->route('admin.users'); } catch (DisplayException $ex) { @@ -142,7 +152,7 @@ class UserController extends Controller */ public function update(UserFormRequest $request, User $user) { - $this->service->update($user, $request->normalize()); + $this->service->update($user->id, $request->normalize()); $this->alert->success('User account has been updated.')->flash(); return redirect()->route('admin.users.view', $user->id); @@ -156,7 +166,7 @@ class UserController extends Controller */ public function json(Request $request) { - return User::search($request->input('q'))->all([ + return $this->userModel->search($request->input('q'))->all([ 'id', 'email', 'username', 'name_first', 'name_last', ])->transform(function ($item) { $item->md5 = md5(strtolower($item->email)); diff --git a/config/pterodactyl.php b/config/pterodactyl.php index bd10183c6..d1e74ae0c 100644 --- a/config/pterodactyl.php +++ b/config/pterodactyl.php @@ -39,6 +39,9 @@ return [ 'frontend' => [ 'servers' => env('APP_PAGINATE_FRONT_SERVERS', 15), ], + 'admin' => [ + 'users' => env('APP_PAGINATE_ADMIN_USERS', 25), + ], 'api' => [ 'nodes' => env('APP_PAGINATE_API_NODES', 25), 'servers' => env('APP_PAGINATE_API_SERVERS', 25),