Merge branch 'develop' into feature/fixed-seeders

This commit is contained in:
Dane Everitt 2017-11-04 12:50:32 -05:00
commit 233cbfda09
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 41 additions and 46 deletions

View file

@ -6,9 +6,10 @@ use Closure;
use Illuminate\Http\Request;
use Pterodactyl\Models\Server;
use Illuminate\Contracts\Session\Session;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class AccessingValidServer
@ -23,6 +24,11 @@ class AccessingValidServer
*/
private $repository;
/**
* @var \Illuminate\Contracts\Routing\ResponseFactory
*/
private $response;
/**
* @var \Illuminate\Contracts\Session\Session
*/
@ -32,16 +38,19 @@ class AccessingValidServer
* AccessingValidServer constructor.
*
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Illuminate\Contracts\Routing\ResponseFactory $response
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
* @param \Illuminate\Contracts\Session\Session $session
*/
public function __construct(
ConfigRepository $config,
ResponseFactory $response,
ServerRepositoryInterface $repository,
Session $session
) {
$this->config = $config;
$this->repository = $repository;
$this->response = $response;
$this->session = $session;
}
@ -63,30 +72,22 @@ class AccessingValidServer
$isApiRequest = $request->expectsJson() || $request->is(...$this->config->get('pterodactyl.json_routes', []));
$server = $this->repository->getByUuid($attributes instanceof Server ? $attributes->uuid : $attributes);
if (! $server) {
if ($isApiRequest) {
throw new NotFoundHttpException('The requested server was not found on the system.');
}
return response()->view('errors.404', [], 404);
}
if ($server->suspended) {
if ($isApiRequest) {
throw new AccessDeniedHttpException('Server is suspended.');
throw new AccessDeniedHttpException('Server is suspended and cannot be accessed.');
}
return response()->view('errors.suspended', [], 403);
return $this->response->view('errors.suspended', [], 403);
}
// Servers can have install statuses other than 1 or 0, so don't check
// for a bool-type operator here.
if ($server->installed !== 1) {
if ($isApiRequest) {
throw new AccessDeniedHttpException('Server is not marked as installed.');
throw new ConflictHttpException('Server is still completing the installation process.');
}
return response()->view('errors.installing', [], 403);
return $this->response->view('errors.installing', [], 409);
}
// Store the server in the session.