Push initial implementations of new repository structure

This breaks almost the entire panel, do not pull this branch in this state.

Mostly just moved old repository files to a new folder without updating anything else in order to start doing new things. Structure is not finalized.
This commit is contained in:
Dane Everitt 2017-06-10 22:28:44 -05:00
parent 65957e7ea5
commit 5c2b9deb09
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
39 changed files with 1083 additions and 166 deletions

View file

@ -25,7 +25,7 @@
namespace Pterodactyl\Console\Commands; namespace Pterodactyl\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Pterodactyl\Repositories\UserRepository; use Pterodactyl\Repositories\oldUserRepository;
class MakeUser extends Command class MakeUser extends Command
{ {
@ -80,7 +80,7 @@ class MakeUser extends Command
$data['root_admin'] = is_null($this->option('admin')) ? $this->confirm('Is this user a root administrator?') : $this->option('admin'); $data['root_admin'] = is_null($this->option('admin')) ? $this->confirm('Is this user a root administrator?') : $this->option('admin');
try { try {
$user = new UserRepository; $user = new oldUserRepository;
$user->create($data); $user->create($data);
return $this->info('User successfully created.'); return $this->info('User successfully created.');

View file

@ -0,0 +1,39 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Contracts\Criteria;
use Pterodactyl\Repositories\Repository;
interface CriteriaInterface
{
/**
* Apply selected criteria to a repository call.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param \Pterodactyl\Repositories\Repository $repository
* @return mixed
*/
public function apply($model, Repository $repository);
}

View file

@ -0,0 +1,164 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Contracts\Repositories;
use Illuminate\Container\Container;
interface RepositoryInterface
{
/**
* RepositoryInterface constructor.
*
* @param \Illuminate\Container\Container $container
*/
public function __construct(Container $container);
/**
* Define the model class to be loaded.
*
* @return string
*/
public function model();
/**
* Returns the raw model class.
*
* @return \Illuminate\Database\Eloquent\Model
*/
public function getModel();
/**
* Make the model instance.
*
* @return \Illuminate\Database\Eloquent\Model
* @throws \Pterodactyl\Exceptions\Repository\RepositoryException
*/
public function makeModel();
/**
* Return all of the currently defined rules.
*
* @return array
*/
public function getRules();
/**
* Return the rules to apply when updating a model.
*
* @return array
*/
public function getUpdateRules();
/**
* Return the rules to apply when creating a model.
*
* @return array
*/
public function getCreateRules();
/**
* Add relations to a model for retrieval.
*
* @param array $params
* @return $this
*/
public function with(...$params);
/**
* Add count of related items to model when retrieving.
*
* @param array $params
* @return $this
*/
public function withCount(...$params);
/**
* Get all records from the database.
*
* @param array $columns
* @return mixed
*/
public function all(array $columns = ['*']);
/**
* Return a paginated result set.
*
* @param int $limit
* @param array $columns
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function paginate($limit = 15, array $columns = ['*']);
/**
* Create a new record on the model.
*
* @param array $data
* @return \Illuminate\Database\Eloquent\Model
*/
public function create(array $data);
/**
* Update the model.
*
* @param $attributes
* @param array $data
* @return int
*/
public function update($attributes, array $data);
/**
* Delete a model from the database. Handles soft deletion.
*
* @param int $id
* @return mixed
*/
public function delete($id);
/**
* Destroy the model from the database. Ignores soft deletion.
*
* @param int $id
* @return mixed
*/
public function destroy($id);
/**
* Find a given model by ID or IDs.
*
* @param int|array $id
* @param array $columns
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection
*/
public function find($id, array $columns = ['*']);
/**
* Finds the first record matching a passed array of values.
*
* @param array $attributes
* @param array $columns
* @return \Illuminate\Database\Eloquent\Model
*/
public function findBy(array $attributes, array $columns = ['*']);
}

View file

@ -0,0 +1,36 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Contracts\Repositories;
interface SearchableRepositoryInterface extends RepositoryInterface
{
/**
* Pass parameters to search trait on model.
*
* @param string $term
* @return mixed
*/
public function search($term);
}

View file

@ -0,0 +1,30 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Contracts\Repositories;
interface UserInterface extends RepositoryInterface, SearchableRepositoryInterface
{
//
}

View file

@ -26,7 +26,7 @@ namespace Pterodactyl\Exceptions;
use Log; use Log;
class DisplayException extends \Exception class DisplayException extends PterodactylException
{ {
/** /**
* Exception constructor. * Exception constructor.

View file

@ -24,7 +24,7 @@
namespace Pterodactyl\Exceptions; namespace Pterodactyl\Exceptions;
class DisplayValidationException extends \Exception class DisplayValidationException extends PterodactylException
{ {
// //
} }

View file

@ -0,0 +1,30 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Exceptions;
class PterodactylException extends \Exception
{
//
}

View file

@ -0,0 +1,30 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Exceptions\Repository;
class RepositoryException extends \Exception
{
//
}

View file

@ -30,7 +30,7 @@ use Illuminate\Http\Request;
use Pterodactyl\Models\User; use Pterodactyl\Models\User;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\UserRepository; use Pterodactyl\Repositories\oldUserRepository;
use Pterodactyl\Transformers\Admin\UserTransformer; use Pterodactyl\Transformers\Admin\UserTransformer;
use Pterodactyl\Exceptions\DisplayValidationException; use Pterodactyl\Exceptions\DisplayValidationException;
use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Pagination\IlluminatePaginatorAdapter;
@ -91,7 +91,7 @@ class UserController extends Controller
{ {
$this->authorize('user-create', $request->apiKey()); $this->authorize('user-create', $request->apiKey());
$repo = new UserRepository; $repo = new oldUserRepository;
try { try {
$user = $repo->create($request->only([ $user = $repo->create($request->only([
'custom_id', 'email', 'password', 'name_first', 'custom_id', 'email', 'password', 'name_first',
@ -128,7 +128,7 @@ class UserController extends Controller
{ {
$this->authorize('user-edit', $request->apiKey()); $this->authorize('user-edit', $request->apiKey());
$repo = new UserRepository; $repo = new oldUserRepository;
try { try {
$user = $repo->update($user, $request->intersect([ $user = $repo->update($user, $request->intersect([
'email', 'password', 'name_first', 'email', 'password', 'name_first',
@ -165,7 +165,7 @@ class UserController extends Controller
{ {
$this->authorize('user-delete', $request->apiKey()); $this->authorize('user-delete', $request->apiKey());
$repo = new UserRepository; $repo = new oldUserRepository;
try { try {
$repo->delete($id); $repo->delete($id);

View file

@ -26,8 +26,10 @@ namespace Pterodactyl\Http\Controllers\Admin;
use Log; use Log;
use Alert; use Alert;
use Route;
use Javascript; use Javascript;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Http\Requests\Admin\Service\EditOptionScript;
use Pterodactyl\Models\Service; use Pterodactyl\Models\Service;
use Pterodactyl\Models\ServiceOption; use Pterodactyl\Models\ServiceOption;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
@ -39,6 +41,21 @@ use Pterodactyl\Http\Requests\Admin\Service\StoreOptionVariable;
class OptionController extends Controller class OptionController extends Controller
{ {
/**
* Store the repository instance.
*
* @var \Pterodactyl\Repositories\OptionRepository
*/
protected $repository;
/**
* OptionController constructor.
*/
public function __construct()
{
$this->repository = new OptionRepository(Route::current()->parameter('option'));
}
/** /**
* Handles request to view page for adding new option. * Handles request to view page for adding new option.
* *
@ -227,24 +244,17 @@ class OptionController extends Controller
} }
/** /**
* Handles POST when updating scripts for a service option. * Handles POST when updating script for a service option.
* *
* @param Request $request * @param \Pterodactyl\Http\Requests\Admin\Service\EditOptionScript $request
* @param int $id * @return \Illuminate\Http\RedirectResponse
* @return \Illuminate\Response\RedirectResponse
*/ */
public function updateScripts(Request $request, $id) public function updateScripts(EditOptionScript $request)
{ {
$repo = new OptionRepository;
try { try {
$repo->scripts($id, $request->only([ $this->repository->scripts($request->normalize());
'script_install', 'script_entry',
'script_container', 'copy_script_from',
]));
Alert::success('Successfully updated option scripts to be run when servers are installed.')->flash(); Alert::success('Successfully updated option scripts to be run when servers are installed.')->flash();
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.services.option.scripts', $id)->withErrors(json_decode($ex->getMessage()));
} catch (DisplayException $ex) { } catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash(); Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) { } catch (\Exception $ex) {

View file

@ -25,17 +25,31 @@
namespace Pterodactyl\Http\Controllers\Admin; namespace Pterodactyl\Http\Controllers\Admin;
use Log;
use Alert; use Alert;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Models\User; use Pterodactyl\Contracts\Repositories\UserInterface;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Http\Requests\Admin\UserFormRequest;
use Pterodactyl\Models\User;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\UserRepository;
use Pterodactyl\Exceptions\DisplayValidationException;
class UserController extends Controller class UserController extends Controller
{ {
/**
* @var \Pterodactyl\Repositories\Eloquent\UserRepository
*/
protected $repository;
/**
* UserController constructor.
*
* @param \Pterodactyl\Contracts\Repositories\UserInterface $repository
*/
public function __construct(UserInterface $repository)
{
$this->repository = $repository;
}
/** /**
* Display user index page. * Display user index page.
* *
@ -44,7 +58,7 @@ class UserController extends Controller
*/ */
public function index(Request $request) public function index(Request $request)
{ {
$users = User::withCount('servers', 'subuserOf'); $users = $this->repository->withCount('servers', 'subuserOf');
if (! is_null($request->input('query'))) { if (! is_null($request->input('query'))) {
$users->search($request->input('query')); $users->search($request->input('query'));
@ -58,10 +72,9 @@ class UserController extends Controller
/** /**
* Display new user page. * Display new user page.
* *
* @param \Illuminate\Http\Request $request
* @return \Illuminate\View\View * @return \Illuminate\View\View
*/ */
public function create(Request $request) public function create()
{ {
return view('admin.users.new'); return view('admin.users.new');
} }
@ -69,96 +82,61 @@ class UserController extends Controller
/** /**
* Display user view page. * Display user view page.
* *
* @param \Illuminate\Http\Request $request * @param \Pterodactyl\Models\User $user
* @param int $id
* @return \Illuminate\View\View * @return \Illuminate\View\View
*/ */
public function view(Request $request, $id) public function view(User $user)
{ {
return view('admin.users.view', [ return view('admin.users.view', [
'user' => User::with('servers.node')->findOrFail($id), 'user' => $user,
]); ]);
} }
/** /**
* Delete a user. * Delete a user from the system.
* *
* @param \Illuminate\Http\Request $request * @param \Pterodactyl\Models\User $user
* @param int $id
* @return \Illuminate\Http\RedirectResponse * @return \Illuminate\Http\RedirectResponse
*/ */
public function delete(Request $request, $id) public function delete(User $user)
{ {
try { try {
$repo = new UserRepository; $this->repository->delete($user->id);
$repo->delete($id);
Alert::success('Successfully deleted user from system.')->flash();
return redirect()->route('admin.users'); return redirect()->route('admin.users');
} catch (DisplayException $ex) { } catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash(); Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An exception was encountered while attempting to delete this user.')->flash();
} }
return redirect()->route('admin.users.view', $id); return redirect()->route('admin.users.view', $user->id);
} }
/** /**
* Create a user. * Create a user.
* *
* @param \Illuminate\Http\Request $request * @param \Pterodactyl\Http\Requests\Admin\UserFormRequest $request
* @return \Illuminate\Http\RedirectResponse * @return \Illuminate\Http\RedirectResponse
*/ */
public function store(Request $request) public function store(UserFormRequest $request)
{ {
try { $user = $this->repository->create($request->normalize());
$user = new UserRepository;
$userid = $user->create($request->only([
'email', 'password', 'name_first',
'name_last', 'username', 'root_admin',
]));
Alert::success('Account has been successfully created.')->flash(); Alert::success('Account has been successfully created.')->flash();
return redirect()->route('admin.users.view', $userid); return redirect()->route('admin.users.view', $user->id);
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.users.new')->withErrors(json_decode($ex->getMessage()))->withInput();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An error occured while attempting to add a new user.')->flash();
return redirect()->route('admin.users.new');
}
} }
/** /**
* Update a user. * Update a user on the system.
* *
* @param \Illuminate\Http\Request $request * @param \Pterodactyl\Http\Requests\Admin\UserFormRequest $request
* @param int $id * @param \Pterodactyl\Models\User $user
* @return \Illuminate\Http\RedirectResponse * @return \Illuminate\Http\RedirectResponse
*/ */
public function update(Request $request, $id) public function update(UserFormRequest $request, User $user)
{ {
try { $this->repository->update($user->id, $request->normalize());
$repo = new UserRepository;
$user = $repo->update($id, array_merge(
$request->only('root_admin'),
$request->intersect([
'email', 'password', 'name_first',
'name_last', 'username',
])
));
Alert::success('User account was successfully updated.')->flash();
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.users.view', $id)->withErrors(json_decode($ex->getMessage()));
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An error occured while attempting to update this user.')->flash();
}
return redirect()->route('admin.users.view', $id); return redirect()->route('admin.users.view', $user->id);
} }
/** /**
@ -169,9 +147,9 @@ class UserController extends Controller
*/ */
public function json(Request $request) public function json(Request $request)
{ {
return User::select('id', 'email', 'username', 'name_first', 'name_last') return $this->repository->search($request->input('q'))->all([
->search($request->input('q')) 'id', 'email', 'username', 'name_first', 'name_last',
->get()->transform(function ($item) { ])->transform(function ($item) {
$item->md5 = md5(strtolower($item->email)); $item->md5 = md5(strtolower($item->email));
return $item; return $item;

View file

@ -30,7 +30,7 @@ use Alert;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Models\User; use Pterodactyl\Models\User;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\UserRepository; use Pterodactyl\Repositories\oldUserRepository;
use Pterodactyl\Exceptions\DisplayValidationException; use Pterodactyl\Exceptions\DisplayValidationException;
class AccountController extends Controller class AccountController extends Controller
@ -90,7 +90,7 @@ class AccountController extends Controller
} }
try { try {
$repo = new UserRepository; $repo = new oldUserRepository;
$repo->update($request->user()->id, $data); $repo->update($request->user()->id, $data);
Alert::success('Your account details were successfully updated.')->flash(); Alert::success('Your account details were successfully updated.')->flash();
} catch (DisplayValidationException $ex) { } catch (DisplayValidationException $ex) {

View file

@ -0,0 +1,59 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Http\Requests\Admin;
use Pterodactyl\Models\User;
use Illuminate\Foundation\Http\FormRequest;
abstract class AdminFormRequest extends FormRequest
{
/**
* Determine if the user is an admin and has permission to access this
* form controller in the first place.
*
* @return bool
*/
public function authorize()
{
if (! $this->user() instanceof User) {
return false;
}
return $this->user()->isRootAdmin();
}
/**
* Return only the fields that we are interested in from the request.
* This will include empty fields as a null value.
*
* @return array
*/
public function normalize()
{
return $this->only(
array_keys($this->rules())
);
}
}

View file

@ -0,0 +1,46 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Http\Requests\Admin\Service;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
class EditOptionScript extends AdminFormRequest
{
/**
* Return the rules to be used when validating the sent data in the request.
*
* @return array
*/
public function rules()
{
return [
'script_install' => 'sometimes|nullable|string',
'script_is_privileged' => 'sometimes|required|boolean',
'script_entry' => 'sometimes|required|string',
'script_container' => 'sometimes|required|string',
'copy_script_from' => 'sometimes|nullable|numeric',
];
}
}

View file

@ -24,25 +24,10 @@
namespace Pterodactyl\Http\Requests\Admin\Service; namespace Pterodactyl\Http\Requests\Admin\Service;
use Pterodactyl\Models\User; use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
use Illuminate\Foundation\Http\FormRequest;
class StoreOptionVariable extends FormRequest class StoreOptionVariable extends AdminFormRequest
{ {
/**
* Determine if user is allowed to access this request.
*
* @return bool
*/
public function authorize()
{
if (! $this->user() instanceof User) {
return false;
}
return $this->user()->isRootAdmin();
}
/** /**
* Set the rules to be used for data passed to the request. * Set the rules to be used for data passed to the request.
* *
@ -59,17 +44,4 @@ class StoreOptionVariable extends FormRequest
'options' => 'sometimes|required|array', 'options' => 'sometimes|required|array',
]; ];
} }
/**
* Return only the fields that we are interested in from the request.
* This will include empty fields as a null value.
*
* @return array
*/
public function normalize()
{
return $this->only(
array_keys($this->rules())
);
}
} }

View file

@ -0,0 +1,79 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Http\Requests\Admin;
use Pterodactyl\Models\User;
use Illuminate\Support\Facades\Hash;
use Pterodactyl\Contracts\Repositories\UserInterface;
class UserFormRequest extends AdminFormRequest
{
/**
* {@inheritdoc}
*/
public function repository()
{
return UserInterface::class;
}
/**
* {@inheritdoc}
*/
public function rules()
{
if ($this->method() === 'PATCH') {
return [
'email' => 'sometimes|required|email|unique:users,email,' . $this->user->id,
'username' => 'sometimes|required|alpha_dash|between:1,255|unique:users,username, ' . $this->user->id . '|' . User::USERNAME_RULES,
'name_first' => 'sometimes|required|string|between:1,255',
'name_last' => 'sometimes|required|string|between:1,255',
'password' => 'sometimes|nullable|' . User::PASSWORD_RULES,
'root_admin' => 'sometimes|required|boolean',
'language' => 'sometimes|required|string|min:1|max:5',
'use_totp' => 'sometimes|required|boolean',
'totp_secret' => 'sometimes|required|size:16',
];
}
return [
'email' => 'required|email|unique:users,email,' . $this->user->id,
'username' => 'required|alpha_dash|between:1,255|unique:users,username,' . $this->user->id . '|' . User::USERNAME_RULES,
'name_first' => 'required|string|between:1,255',
'name_last' => 'required|string|between:1,255',
'password' => 'sometimes|nullable|' . User::PASSWORD_RULES,
'root_admin' => 'required|boolean',
'external_id' => 'sometimes|nullable|numeric|unique:users,external_id',
];
}
public function normalize()
{
if ($this->has('password')) {
$this->merge(['password' => Hash::make($this->input('password'))]);
}
return parent::normalize();
}
}

View file

@ -117,6 +117,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
* *
* @param int $token * @param int $token
* @return bool * @return bool
* @deprecated
*/ */
public function toggleTotp($token) public function toggleTotp($token)
{ {
@ -139,6 +140,8 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
* @param string $password * @param string $password
* @param string $regex * @param string $regex
* @return void * @return void
* @throws \Pterodactyl\Exceptions\DisplayException
* @deprecated
*/ */
public function setPassword($password, $regex = '((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})') public function setPassword($password, $regex = '((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})')
{ {
@ -165,6 +168,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
* Return true or false depending on wether the user is root admin or not. * Return true or false depending on wether the user is root admin or not.
* *
* @return bool * @return bool
* @deprecated
*/ */
public function isRootAdmin() public function isRootAdmin()
{ {
@ -256,6 +260,16 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
return $query; return $query;
} }
/**
* Store the username as a lowecase string.
*
* @param string $value
*/
public function setUsernameAttribute($value)
{
$this->attributes['username'] = strtolower($value);
}
/** /**
* Returns all permissions that a user has. * Returns all permissions that a user has.
* *

View file

@ -30,9 +30,17 @@ use Carbon;
use Pterodactyl\Events; use Pterodactyl\Events;
use Pterodactyl\Models\User; use Pterodactyl\Models\User;
use Pterodactyl\Notifications\AccountCreated; use Pterodactyl\Notifications\AccountCreated;
use Pterodactyl\Services\UuidService;
class UserObserver class UserObserver
{ {
protected $uuid;
public function __construct(UuidService $uuid)
{
$this->uuid = $uuid;
}
/** /**
* Listen to the User creating event. * Listen to the User creating event.
* *
@ -41,6 +49,8 @@ class UserObserver
*/ */
public function creating(User $user) public function creating(User $user)
{ {
$user->uuid = $this->uuid->generate();
event(new Events\User\Creating($user)); event(new Events\User\Creating($user));
} }
@ -52,8 +62,7 @@ class UserObserver
*/ */
public function created(User $user) public function created(User $user)
{ {
event(new Events\User\Created($user)); dd($user);
if ($user->password === 'unset') { if ($user->password === 'unset') {
$token = hash_hmac('sha256', str_random(40), config('app.key')); $token = hash_hmac('sha256', str_random(40), config('app.key'));
DB::table('password_resets')->insert([ DB::table('password_resets')->insert([
@ -68,6 +77,8 @@ class UserObserver
'username' => $user->username, 'username' => $user->username,
'token' => (isset($token)) ? $token : null, 'token' => (isset($token)) ? $token : null,
])); ]));
event(new Events\User\Created($user));
} }
/** /**

View file

@ -0,0 +1,40 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Providers;
use Illuminate\Support\ServiceProvider;
use Pterodactyl\Contracts\Repositories\UserInterface;
use Pterodactyl\Repositories\Eloquent\UserRepository;
class RepositoryServiceProvider extends ServiceProvider
{
/**
* Register the repositories.
*/
public function register()
{
$this->app->bind(UserInterface::class, UserRepository::class);
}
}

View file

@ -0,0 +1,78 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\User;
use Illuminate\Contracts\Auth\Guard;
use Pterodactyl\Repositories\Repository;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Contracts\Repositories\UserInterface;
class UserRepository extends Repository implements UserInterface
{
/**
* Dependencies to automatically inject into the repository.
*
* @var array
*/
protected $inject = [
'guard' => Guard::class,
];
/**
* Return the model to be used for the repository.
*
* @return string
*/
public function model()
{
return User::class;
}
/**
* {@inheritdoc}
*/
public function search($term)
{
$this->model->search($term);
return $this;
}
public function delete($id)
{
$user = $this->model->withCount('servers')->find($id);
if ($this->guard->user() && $this->guard->user()->id === $user->id) {
throw new DisplayException('You cannot delete your own account.');
}
if ($user->server_count > 0) {
throw new DisplayException('Cannot delete an account that has active servers attached to it.');
}
return $user->delete();
}
}

View file

@ -26,12 +26,67 @@ namespace Pterodactyl\Repositories;
use DB; use DB;
use Validator; use Validator;
use InvalidArgumentException;
use Pterodactyl\Models\ServiceOption; use Pterodactyl\Models\ServiceOption;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Exceptions\DisplayValidationException; use Pterodactyl\Exceptions\DisplayValidationException;
class OptionRepository class OptionRepository
{ {
/**
* Store the requested service option.
*
* @var \Pterodactyl\Models\ServiceOption
*/
protected $model;
/**
* OptionRepository constructor.
*
* @param null|int|\Pterodactyl\Models\ServiceOption $option
*/
public function __construct($option = null)
{
if (is_null($option)) {
return;
}
if ($option instanceof ServiceOption) {
$this->model = $option;
} else {
if (! is_numeric($option)) {
throw new InvalidArgumentException(
sprintf('Variable passed to constructor must be integer or instance of \Pterodactyl\Models\ServiceOption.')
);
}
$this->model = ServiceOption::findOrFail($option);
}
}
/**
* Return the eloquent model for the given repository.
*
* @return null|\Pterodactyl\Models\ServiceOption
*/
public function getModel()
{
return $this->model;
}
/**
* Update the currently assigned model by re-initalizing the class.
*
* @param null|int|\Pterodactyl\Models\ServiceOption $option
* @return $this
*/
public function setModel($option)
{
self::__construct($option);
return $this;
}
/** /**
* Creates a new service option on the system. * Creates a new service option on the system.
* *
@ -67,7 +122,7 @@ class OptionRepository
} }
} }
return ServiceOption::create($data); return $this->setModel(ServiceOption::create($data))->getModel();
} }
/** /**
@ -76,13 +131,15 @@ class OptionRepository
* @param int $id * @param int $id
* @return void * @return void
* *
* @throws \Exception
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Throwable
*/ */
public function delete($id) public function delete($id)
{ {
$option = ServiceOption::with('variables')->withCount('servers')->findOrFail($id); $this->model->load('variables', 'servers');
if ($option->servers_count > 0) { if ($this->model->servers->count() > 0) {
throw new DisplayException('You cannot delete a service option that has servers associated with it.'); throw new DisplayException('You cannot delete a service option that has servers associated with it.');
} }
@ -158,32 +215,19 @@ class OptionRepository
/** /**
* Updates a service option's scripts in the database. * Updates a service option's scripts in the database.
* *
* @param int $id
* @param array $data * @param array $data
* @return \Pterodactyl\Models\ServiceOption
* *
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\DisplayValidationException
*/ */
public function scripts($id, array $data) public function scripts(array $data)
{ {
$option = ServiceOption::findOrFail($id);
$data['script_install'] = empty($data['script_install']) ? null : $data['script_install']; $data['script_install'] = empty($data['script_install']) ? null : $data['script_install'];
$validator = Validator::make($data, [
'script_install' => 'sometimes|nullable|string',
'script_is_privileged' => 'sometimes|required|boolean',
'script_entry' => 'sometimes|required|string',
'script_container' => 'sometimes|required|string',
'copy_script_from' => 'sometimes|nullable|numeric',
]);
if (isset($data['copy_script_from']) && ! empty($data['copy_script_from'])) { if (isset($data['copy_script_from']) && ! empty($data['copy_script_from'])) {
$select = ServiceOption::whereNull('copy_script_from')->where([ $select = ServiceOption::whereNull('copy_script_from')
['id', $data['copy_script_from']], ->where('id', $data['copy_script_from'])
['service_id', $option->service_id], ->where('service_id', $this->model->service_id)
])->first(); ->first();
if (! $select) { if (! $select) {
throw new DisplayException('The service option selected to copy a script from either does not exist, or is copying from a higher level.'); throw new DisplayException('The service option selected to copy a script from either does not exist, or is copying from a higher level.');
@ -192,12 +236,6 @@ class OptionRepository
$data['copy_script_from'] = null; $data['copy_script_from'] = null;
} }
if ($validator->fails()) { $this->model->fill($data)->save();
throw new DisplayValidationException(json_encode($validator->errors()));
}
$option->fill($data)->save();
return $option;
} }
} }

View file

@ -79,7 +79,7 @@ class SubuserRepository
$user = User::where('email', $data['email'])->first(); $user = User::where('email', $data['email'])->first();
if (! $user) { if (! $user) {
try { try {
$repo = new UserRepository; $repo = new oldUserRepository;
$user = $repo->create([ $user = $repo->create([
'email' => $data['email'], 'email' => $data['email'],
'username' => str_random(8), 'username' => str_random(8),

View file

@ -43,7 +43,7 @@ use Pterodactyl\Services\DeploymentService;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Exceptions\DisplayValidationException; use Pterodactyl\Exceptions\DisplayValidationException;
class ServerRepository class old_ServerRepository
{ {
/** /**
* An array of daemon permission to assign to this server. * An array of daemon permission to assign to this server.

View file

@ -35,7 +35,7 @@ use Pterodactyl\Services\UuidService;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Exceptions\DisplayValidationException; use Pterodactyl\Exceptions\DisplayValidationException;
class UserRepository class old_UserRepository
{ {
/** /**
* Creates a user on the panel. Returns the created user's ID. * Creates a user on the panel. Returns the created user's ID.

View file

@ -0,0 +1,229 @@
<?php
/*
* Pterodactyl - Panel
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Repositories;
use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Model;
use Pterodactyl\Contracts\Repositories\RepositoryInterface;
use Pterodactyl\Exceptions\Repository\RepositoryException;
abstract class Repository implements RepositoryInterface
{
const RULE_UPDATED = 'updated';
const RULE_CREATED = 'created';
/**
* @var \Illuminate\Container\Container
*/
protected $container;
/**
* Array of classes to inject automatically into the container.
*
* @var array
*/
protected $inject = [];
/**
* @var \Illuminate\Database\Eloquent\Model
*/
protected $model;
/**
* Array of validation rules that can be accessed from this repository.
*
* @var array
*/
protected $rules = [];
/**
* {@inheritdoc}
*/
public function __construct(Container $container)
{
$this->container = $container;
foreach ($this->inject as $key => $value) {
if (isset($this->{$key})) {
throw new \Exception('Cannot override a defined object in this class.');
}
$this->{$key} = $this->container->make($value);
}
$this->makeModel();
}
/**
* {@inheritdoc}
*/
abstract public function model();
/**
* {@inheritdoc}
*/
public function getModel()
{
return $this->model;
}
/**
* {@inheritdoc}
*/
public function makeModel()
{
$model = $this->container->make($this->model());
if (! $model instanceof Model) {
throw new RepositoryException(
"Class {$this->model()} must be an instance of \\Illuminate\\Database\\Eloquent\\Model"
);
}
return $this->model = $model->newQuery();
}
/**
* {@inheritdoc}
*/
public function getRules()
{
return $this->rules;
}
/**
* {@inheritdoc}
*/
public function getUpdateRules()
{
if (array_key_exists(self::RULE_UPDATED, $this->rules)) {
return $this->rules[self::RULE_UPDATED];
}
return [];
}
/**
* {@inheritdoc}
*/
public function getCreateRules()
{
if (array_key_exists(self::RULE_CREATED, $this->rules)) {
return $this->rules[self::RULE_CREATED];
}
return [];
}
/**
* {@inheritdoc}
*/
public function with(...$params)
{
$this->model = $this->model->with($params);
return $this;
}
/**
* {@inheritdoc}
*/
public function withCount(...$params)
{
$this->model = $this->model->withCount($params);
return $this;
}
/**
* {@inheritdoc}
*/
public function all(array $columns = ['*'])
{
return $this->model->get($columns);
}
/**
* {@inheritdoc}
*/
public function paginate($limit = 15, array $columns = ['*'])
{
return $this->model->paginate($limit, $columns);
}
/**
* {@inheritdoc}
*/
public function create(array $data)
{
return $this->model->create($data);
}
/**
* {@inheritdoc}
*/
public function update($attributes, array $data)
{
// If only a number is passed, we assume it is an ID
// for the specific model at hand.
if (is_numeric($attributes)) {
$attributes = [['id', '=', $attributes]];
}
return $this->model->where($attributes)->get()->each->update($data);
}
/**
* {@inheritdoc}
*/
public function delete($id)
{
return $this->model->find($id)->delete();
}
/**
* {@inheritdoc}
*/
public function destroy($id)
{
return $this->model->find($id)->forceDelete();
}
/**
* {@inheritdoc}
*/
public function find($id, array $columns = ['*'])
{
return $this->model->find($id, $columns);
}
/**
* {@inheritdoc}
*/
public function findBy(array $attributes, array $columns = ['*'])
{
return $this->model->where($attributes)->first($columns);
}
}

View file

@ -163,6 +163,7 @@ return [
Pterodactyl\Providers\AppServiceProvider::class, Pterodactyl\Providers\AppServiceProvider::class,
Pterodactyl\Providers\AuthServiceProvider::class, Pterodactyl\Providers\AuthServiceProvider::class,
Pterodactyl\Providers\EventServiceProvider::class, Pterodactyl\Providers\EventServiceProvider::class,
Pterodactyl\Providers\RepositoryServiceProvider::class,
Pterodactyl\Providers\RouteServiceProvider::class, Pterodactyl\Providers\RouteServiceProvider::class,
Pterodactyl\Providers\MacroServiceProvider::class, Pterodactyl\Providers\MacroServiceProvider::class,
Pterodactyl\Providers\PhraseAppTranslationProvider::class, Pterodactyl\Providers\PhraseAppTranslationProvider::class,

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddExternalIdToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->unsignedInteger('external_id')->after('id')->nullable()->unique();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('external_id');
});
}
}

View file

@ -68,6 +68,7 @@
</div> </div>
<div class="box-footer"> <div class="box-footer">
{!! csrf_field() !!} {!! csrf_field() !!}
{!! method_field('PATCH') !!}
<input type="submit" value="Update User" class="btn btn-primary btn-sm"> <input type="submit" value="Update User" class="btn btn-primary btn-sm">
</div> </div>
</div> </div>

View file

@ -81,12 +81,12 @@ Route::group(['prefix' => 'users'], function () {
Route::get('/', 'UserController@index')->name('admin.users'); Route::get('/', 'UserController@index')->name('admin.users');
Route::get('/accounts.json', 'UserController@json')->name('admin.users.json'); Route::get('/accounts.json', 'UserController@json')->name('admin.users.json');
Route::get('/new', 'UserController@create')->name('admin.users.new'); Route::get('/new', 'UserController@create')->name('admin.users.new');
Route::get('/view/{id}', 'UserController@view')->name('admin.users.view'); Route::get('/view/{user}', 'UserController@view')->name('admin.users.view');
Route::post('/new', 'UserController@store'); Route::post('/new', 'UserController@store');
Route::post('/view/{id}', 'UserController@update'); Route::patch('/view/{user}', 'UserController@update');
Route::delete('/view/{id}', 'UserController@delete'); Route::delete('/view/{user}', 'UserController@delete');
}); });
/* /*
@ -168,17 +168,17 @@ Route::group(['prefix' => 'services'], function () {
Route::get('/view/{id}', 'ServiceController@view')->name('admin.services.view'); Route::get('/view/{id}', 'ServiceController@view')->name('admin.services.view');
Route::get('/view/{id}/functions', 'ServiceController@viewFunctions')->name('admin.services.view.functions'); Route::get('/view/{id}/functions', 'ServiceController@viewFunctions')->name('admin.services.view.functions');
Route::get('/option/new', 'OptionController@create')->name('admin.services.option.new'); Route::get('/option/new', 'OptionController@create')->name('admin.services.option.new');
Route::get('/option/{id}', 'OptionController@viewConfiguration')->name('admin.services.option.view'); Route::get('/option/{option}', 'OptionController@viewConfiguration')->name('admin.services.option.view');
Route::get('/option/{id}/variables', 'OptionController@viewVariables')->name('admin.services.option.variables'); Route::get('/option/{option}/variables', 'OptionController@viewVariables')->name('admin.services.option.variables');
Route::get('/option/{id}/scripts', 'OptionController@viewScripts')->name('admin.services.option.scripts'); Route::get('/option/{option}/scripts', 'OptionController@viewScripts')->name('admin.services.option.scripts');
Route::post('/new', 'ServiceController@store'); Route::post('/new', 'ServiceController@store');
Route::post('/view/{id}', 'ServiceController@edit'); Route::post('/view/{option}', 'ServiceController@edit');
Route::post('/option/new', 'OptionController@store'); Route::post('/option/new', 'OptionController@store');
Route::post('/option/{id}', 'OptionController@editConfiguration'); Route::post('/option/{option}', 'OptionController@editConfiguration');
Route::post('/option/{id}/scripts', 'OptionController@updateScripts'); Route::post('/option/{option}/scripts', 'OptionController@updateScripts');
Route::post('/option/{id}/variables', 'OptionController@createVariable'); Route::post('/option/{option}/variables', 'OptionController@createVariable');
Route::post('/option/{id}/variables/{variable}', 'OptionController@editVariable')->name('admin.services.option.variables.edit'); Route::post('/option/{option}/variables/{variable}', 'OptionController@editVariable')->name('admin.services.option.variables.edit');
Route::delete('/view/{id}', 'ServiceController@delete'); Route::delete('/view/{id}', 'ServiceController@delete');
}); });