Cleanup user and location controllers.

This commit is contained in:
Dane Everitt 2017-06-17 17:36:39 -05:00
parent 8ea907e97a
commit cede747442
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 39 additions and 23 deletions

View file

@ -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) {

View file

@ -1,8 +1,7 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>
* Some Modifications (c) 2015 Dylan Seidt <dylan.seidt@gmail.com>.
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* 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));

View file

@ -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),