This commit is contained in:
Dane Everitt 2017-12-30 20:25:04 -06:00
parent 10e2e6e379
commit 5efee34378
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
11 changed files with 111 additions and 135 deletions

View file

@ -9,6 +9,7 @@ use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Http\Controllers\Controller;
use Illuminate\Contracts\Translation\Translator;
use Pterodactyl\Services\Users\UserUpdateService;
use Pterodactyl\Traits\Helpers\AvailableLanguages;
use Pterodactyl\Services\Users\UserCreationService;
use Pterodactyl\Services\Users\UserDeletionService;
use Pterodactyl\Http\Requests\Admin\UserFormRequest;
@ -16,6 +17,8 @@ use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
class UserController extends Controller
{
use AvailableLanguages;
/**
* @var \Prologue\Alerts\AlertsMessageBag
*/
@ -92,7 +95,9 @@ class UserController extends Controller
*/
public function create()
{
return view('admin.users.new');
return view('admin.users.new', [
'languages' => $this->getAvailableLanguages(true),
]);
}
/**
@ -103,7 +108,10 @@ class UserController extends Controller
*/
public function view(User $user)
{
return view('admin.users.view', ['user' => $user]);
return view('admin.users.view', [
'user' => $user,
'languages' => $this->getAvailableLanguages(true),
]);
}
/**

View file

@ -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\Http\Requests\Admin;
@ -39,11 +32,11 @@ abstract class AdminFormRequest extends FormRequest
* Return only the fields that we are interested in from the request.
* This will include empty fields as a null value.
*
* @param array $only
* @param array|null $only
* @return array
*/
public function normalize($only = [])
public function normalize(array $only = null)
{
return $this->all(empty($only) ? array_keys($this->rules()) : $only);
return $this->only($only ?? array_keys($this->rules()));
}
}

View file

@ -22,12 +22,16 @@ class UserFormRequest extends AdminFormRequest
return User::getCreateRules();
}
public function normalize($only = [])
/**
* @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', 'ignore_connection_error'])
$this->only(['email', 'username', 'name_first', 'name_last', 'root_admin', 'language', 'ignore_connection_error'])
);
}

View file

@ -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\Models;
@ -127,6 +120,8 @@ class User extends Model implements
'name_first' => 'required',
'name_last' => 'required',
'password' => 'sometimes',
'language' => 'sometimes',
'use_totp' => 'sometimes',
];
/**

View file

@ -1,27 +1,14 @@
<?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\Observers;
use Pterodactyl\Events;
use Pterodactyl\Models\User;
use Pterodactyl\Services\Components\UuidService;
class UserObserver
{
protected $uuid;
public function __construct(UuidService $uuid)
{
$this->uuid = $uuid;
}
/**
* Listen to the User creating event.
*
@ -29,8 +16,6 @@ class UserObserver
*/
public function creating(User $user)
{
$user->uuid = $this->uuid->generate('users', 'uuid');
event(new Events\User\Creating($user));
}

View file

@ -1,63 +0,0 @@
<?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\Components;
use DB;
use Uuid;
class UuidService
{
/**
* Generate a unique UUID validating against specified table and column.
* Defaults to `users.uuid`.
*
* @param string $table
* @param string $field
* @param int $type
* @return string
* @deprecated
*/
public function generate($table = 'users', $field = 'uuid', $type = 4)
{
$return = false;
do {
$uuid = Uuid::generate($type);
if (! DB::table($table)->where($field, $uuid)->exists()) {
$return = $uuid;
}
} while (! $return);
return (string) $return;
}
/**
* Generates a ShortUUID code which is 8 characters long and is used for identifying servers in the system.
*
* @param string $table
* @param string $field
* @param null|string $attachedUuid
* @return string
* @deprecated
*/
public function generateShort($table = 'servers', $field = 'uuidShort', $attachedUuid = null)
{
$return = false;
do {
$short = (is_null($attachedUuid)) ? substr(Uuid::generate(4), 0, 8) : substr($attachedUuid, 0, 8);
$attachedUuid = null;
if (! DB::table($table)->where($field, $short)->exists()) {
$return = $short;
}
} while (! $return);
return (string) $return;
}
}

View file

@ -9,6 +9,7 @@
namespace Pterodactyl\Services\Users;
use Ramsey\Uuid\Uuid;
use Illuminate\Foundation\Application;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Database\ConnectionInterface;
@ -96,7 +97,10 @@ class UserCreationService
$token = $this->passwordService->handle($data['email']);
}
$user = $this->repository->create($data);
$user = $this->repository->create(array_merge($data, [
'uuid' => Uuid::uuid4()->toString(),
]));
$this->connection->commit();
// @todo fire event, handle notification there