Merge branch 'develop' into feature/api-v1
This commit is contained in:
commit
d21f70c04b
20 changed files with 205 additions and 231 deletions
|
@ -95,11 +95,10 @@ class FileActionsController extends Controller
|
|||
* @param string $file
|
||||
* @return \Illuminate\View\View
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function update(UpdateFileContentsFormRequest $request, string $uuid, string $file): View
|
||||
public function view(UpdateFileContentsFormRequest $request, string $uuid, string $file): View
|
||||
{
|
||||
$server = $request->attributes->get('server');
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ class RemoteRequestController extends Controller
|
|||
$this->repository->setNode($server->node_id)
|
||||
->setAccessServer($server->uuid)
|
||||
->setAccessToken($request->attributes->get('server_token'))
|
||||
->putContent($request->input('file'), $request->input('contents'));
|
||||
->putContent($request->input('file'), $request->input('contents') ?? '');
|
||||
|
||||
return response('', 204);
|
||||
} catch (RequestException $exception) {
|
||||
|
|
|
@ -7,34 +7,21 @@ use Pterodactyl\Models\User;
|
|||
class UserFormRequest extends AdminFormRequest
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Rules to apply to requests for updating or creating a user
|
||||
* in the Admin CP.
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = collect(User::getCreateRules());
|
||||
if ($this->method() === 'PATCH') {
|
||||
$rules = User::getUpdateRulesForId($this->route()->parameter('user')->id);
|
||||
|
||||
return array_merge($rules, [
|
||||
'ignore_connection_error' => 'sometimes|nullable|boolean',
|
||||
$rules = collect(User::getUpdateRulesForId($this->route()->parameter('user')->id))->merge([
|
||||
'ignore_connection_error' => ['sometimes', 'nullable', 'boolean'],
|
||||
]);
|
||||
}
|
||||
|
||||
return User::getCreateRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $only
|
||||
* @return array
|
||||
*/
|
||||
public function normalize(array $only = null)
|
||||
{
|
||||
if ($this->method === 'PATCH') {
|
||||
return array_merge(
|
||||
$this->all(['password']),
|
||||
$this->only(['email', 'username', 'name_first', 'name_last', 'root_admin', 'language', 'ignore_connection_error'])
|
||||
);
|
||||
}
|
||||
|
||||
return parent::normalize();
|
||||
return $rules->only([
|
||||
'email', 'username', 'name_first', 'name_last', 'password',
|
||||
'language', 'ignore_connection_error', 'root_admin',
|
||||
])->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace Pterodactyl\Http\Requests\Server;
|
|||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
use Pterodactyl\Exceptions\Http\Server\FileSizeTooLargeException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Http\Server\FileTypeNotEditableException;
|
||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
|
@ -80,7 +81,12 @@ class UpdateFileContentsFormRequest extends ServerFormRequest
|
|||
->setAccessToken($token)
|
||||
->getFileStat($this->route()->parameter('file'));
|
||||
} catch (RequestException $exception) {
|
||||
throw new DaemonConnectionException($exception);
|
||||
switch ($exception->getCode()) {
|
||||
case 404:
|
||||
throw new NotFoundHttpException;
|
||||
default:
|
||||
throw new DaemonConnectionException($exception);
|
||||
}
|
||||
}
|
||||
|
||||
if (! $stats->file || ! in_array($stats->mime, $config->get('pterodactyl.files.editable'))) {
|
||||
|
|
|
@ -76,7 +76,7 @@ class Server extends Model implements CleansAttributes, ValidableContract
|
|||
'owner_id' => 'exists:users,id',
|
||||
'name' => 'regex:/^([\w .-]{1,200})$/',
|
||||
'node_id' => 'exists:nodes,id',
|
||||
'description' => 'nullable|string',
|
||||
'description' => 'string',
|
||||
'memory' => 'numeric|min:0',
|
||||
'swap' => 'numeric|min:-1',
|
||||
'io' => 'numeric|between:10,1000',
|
||||
|
|
|
@ -115,6 +115,7 @@ class User extends Model implements
|
|||
* @var array
|
||||
*/
|
||||
protected static $applicationRules = [
|
||||
'uuid' => 'required',
|
||||
'email' => 'required',
|
||||
'username' => 'required',
|
||||
'name_first' => 'required',
|
||||
|
@ -130,6 +131,7 @@ class User extends Model implements
|
|||
* @var array
|
||||
*/
|
||||
protected static $dataIntegrityRules = [
|
||||
'uuid' => 'string|size:36|unique:users,uuid',
|
||||
'email' => 'email|unique:users,email',
|
||||
'username' => 'alpha_dash|between:1,255|unique:users,username',
|
||||
'name_first' => 'string|between:1,255',
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Notifications;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
@ -19,7 +13,15 @@ class AccountCreated extends Notification implements ShouldQueue
|
|||
use Queueable;
|
||||
|
||||
/**
|
||||
* The password reset token to send.
|
||||
* The authentication token to be used for the user to set their
|
||||
* password for the first time.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $token;
|
||||
|
||||
/**
|
||||
* The user model for the created user.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
|
@ -28,11 +30,13 @@ class AccountCreated extends Notification implements ShouldQueue
|
|||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param aray $user
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @param string|null $token
|
||||
*/
|
||||
public function __construct(array $user)
|
||||
public function __construct(User $user, string $token = null)
|
||||
{
|
||||
$this->user = (object) $user;
|
||||
$this->token = $token;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,12 +60,12 @@ class AccountCreated extends Notification implements ShouldQueue
|
|||
{
|
||||
$message = (new MailMessage)
|
||||
->greeting('Hello ' . $this->user->name . '!')
|
||||
->line('You are recieving this email because an account has been created for you on Pterodactyl Panel.')
|
||||
->line('You are recieving this email because an account has been created for you on ' . config('app.name') . '.')
|
||||
->line('Username: ' . $this->user->username)
|
||||
->line('Email: ' . $notifiable->email);
|
||||
->line('Email: ' . $this->user->email);
|
||||
|
||||
if (! is_null($this->user->token)) {
|
||||
return $message->action('Setup Your Account', url('/auth/password/reset/' . $this->user->token . '?email=' . $notifiable->email));
|
||||
if (! is_null($this->token)) {
|
||||
return $message->action('Setup Your Account', url('/auth/password/reset/' . $this->token . '?email=' . $this->user->email));
|
||||
}
|
||||
|
||||
return $message;
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Servers;
|
||||
|
||||
|
@ -113,6 +106,7 @@ class BuildModificationService
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle($server, array $data)
|
||||
{
|
||||
|
@ -138,11 +132,11 @@ class BuildModificationService
|
|||
}
|
||||
|
||||
$server = $this->repository->update($server->id, [
|
||||
'memory' => array_get($data, 'memory', $server->memory),
|
||||
'swap' => array_get($data, 'swap', $server->swap),
|
||||
'io' => array_get($data, 'io', $server->io),
|
||||
'cpu' => array_get($data, 'cpu', $server->cpu),
|
||||
'disk' => array_get($data, 'disk', $server->disk),
|
||||
'memory' => (int) array_get($data, 'memory', $server->memory),
|
||||
'swap' => (int) array_get($data, 'swap', $server->swap),
|
||||
'io' => (int) array_get($data, 'io', $server->io),
|
||||
'cpu' => (int) array_get($data, 'cpu', $server->cpu),
|
||||
'disk' => (int) array_get($data, 'disk', $server->disk),
|
||||
'allocation_id' => array_get($data, 'allocation_id', $server->allocation_id),
|
||||
]);
|
||||
|
||||
|
|
|
@ -95,9 +95,9 @@ class DetailsModificationService
|
|||
|
||||
$this->connection->beginTransaction();
|
||||
$this->repository->withoutFresh()->update($server->id, [
|
||||
'owner_id' => array_get($data, 'owner_id') ?? $server->owner_id,
|
||||
'name' => array_get($data, 'name') ?? $server->name,
|
||||
'description' => array_get($data, 'description') ?? $server->description,
|
||||
'owner_id' => array_get($data, 'owner_id'),
|
||||
'name' => array_get($data, 'name'),
|
||||
'description' => array_get($data, 'description', ''),
|
||||
], true, true);
|
||||
|
||||
if (array_get($data, 'owner_id') != $server->owner_id) {
|
||||
|
|
|
@ -106,6 +106,7 @@ class ServerCreationService
|
|||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
|
@ -117,7 +118,7 @@ class ServerCreationService
|
|||
'uuidShort' => str_random(8),
|
||||
'node_id' => array_get($data, 'node_id'),
|
||||
'name' => array_get($data, 'name'),
|
||||
'description' => array_get($data, 'description'),
|
||||
'description' => array_get($data, 'description', ''),
|
||||
'skip_scripts' => isset($data['skip_scripts']),
|
||||
'suspended' => false,
|
||||
'owner_id' => array_get($data, 'owner_id'),
|
||||
|
|
|
@ -1,77 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Users;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Notifications\ChannelManager;
|
||||
use Pterodactyl\Notifications\AccountCreated;
|
||||
use Pterodactyl\Services\Helpers\TemporaryPasswordService;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
|
||||
class UserCreationService
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Foundation\Application
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Hashing\Hasher
|
||||
*/
|
||||
protected $hasher;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Notifications\ChannelManager
|
||||
*/
|
||||
protected $notification;
|
||||
private $hasher;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Helpers\TemporaryPasswordService
|
||||
*/
|
||||
protected $passwordService;
|
||||
private $passwordService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* CreationService constructor.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $application
|
||||
* @param \Illuminate\Notifications\ChannelManager $notification
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
|
||||
* @param \Pterodactyl\Services\Helpers\TemporaryPasswordService $passwordService
|
||||
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(
|
||||
Application $application,
|
||||
ChannelManager $notification,
|
||||
ConnectionInterface $connection,
|
||||
Hasher $hasher,
|
||||
TemporaryPasswordService $passwordService,
|
||||
UserRepositoryInterface $repository
|
||||
) {
|
||||
$this->app = $application;
|
||||
$this->connection = $connection;
|
||||
$this->hasher = $hasher;
|
||||
$this->notification = $notification;
|
||||
$this->passwordService = $passwordService;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
@ -97,20 +72,13 @@ class UserCreationService
|
|||
$token = $this->passwordService->handle($data['email']);
|
||||
}
|
||||
|
||||
/** @var \Pterodactyl\Models\User $user */
|
||||
$user = $this->repository->create(array_merge($data, [
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
]));
|
||||
]), true, true);
|
||||
|
||||
$this->connection->commit();
|
||||
|
||||
// @todo fire event, handle notification there
|
||||
$this->notification->send($user, $this->app->makeWith(AccountCreated::class, [
|
||||
'user' => [
|
||||
'name' => $user->name_first,
|
||||
'username' => $user->username,
|
||||
'token' => $token ?? null,
|
||||
],
|
||||
]));
|
||||
$user->notify(new AccountCreated($user, $token ?? null));
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue