2016-02-21 06:15:37 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
2017-06-17 22:36:39 +00:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-02-21 06:15:37 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-02-21 06:15:37 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
2016-12-07 22:46:38 +00:00
|
|
|
use Illuminate\Http\Request;
|
2017-07-01 20:29:49 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
2017-06-17 22:36:39 +00:00
|
|
|
use Pterodactyl\Models\User;
|
2017-06-14 04:25:37 +00:00
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2017-07-22 18:55:30 +00:00
|
|
|
use Pterodactyl\Services\UserService;
|
2016-02-21 06:15:37 +00:00
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-06-17 22:36:39 +00:00
|
|
|
use Pterodactyl\Http\Requests\Admin\UserFormRequest;
|
2016-02-21 06:15:37 +00:00
|
|
|
|
|
|
|
class UserController extends Controller
|
|
|
|
{
|
2017-06-17 22:36:39 +00:00
|
|
|
/**
|
|
|
|
* @var \Prologue\Alerts\AlertsMessageBag
|
|
|
|
*/
|
|
|
|
protected $alert;
|
|
|
|
|
2017-06-11 03:28:44 +00:00
|
|
|
/**
|
2017-07-22 18:55:30 +00:00
|
|
|
* @var \Pterodactyl\Services\UserService
|
2017-06-11 03:28:44 +00:00
|
|
|
*/
|
2017-06-14 04:25:37 +00:00
|
|
|
protected $service;
|
2017-06-11 03:28:44 +00:00
|
|
|
|
2017-06-17 22:36:39 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Models\User
|
|
|
|
*/
|
2017-06-25 00:49:09 +00:00
|
|
|
protected $model;
|
2017-06-17 22:36:39 +00:00
|
|
|
|
2017-07-01 20:29:49 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
2017-06-11 03:28:44 +00:00
|
|
|
/**
|
|
|
|
* UserController constructor.
|
|
|
|
*
|
2017-07-01 20:29:49 +00:00
|
|
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
2017-07-22 18:55:30 +00:00
|
|
|
* @param \Pterodactyl\Services\UserService $service
|
2017-07-01 20:29:49 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
|
|
|
|
* @param \Pterodactyl\Models\User $model
|
2017-06-11 03:28:44 +00:00
|
|
|
*/
|
2017-07-01 20:29:49 +00:00
|
|
|
public function __construct(
|
|
|
|
AlertsMessageBag $alert,
|
|
|
|
UserService $service,
|
|
|
|
UserRepositoryInterface $repository,
|
|
|
|
User $model
|
|
|
|
) {
|
2017-06-14 04:25:37 +00:00
|
|
|
$this->alert = $alert;
|
|
|
|
$this->service = $service;
|
2017-06-25 00:49:09 +00:00
|
|
|
$this->model = $model;
|
2017-07-01 20:29:49 +00:00
|
|
|
$this->repository = $repository;
|
2017-06-11 03:28:44 +00:00
|
|
|
}
|
|
|
|
|
2016-02-21 06:15:37 +00:00
|
|
|
/**
|
2017-03-19 23:36:50 +00:00
|
|
|
* Display user index page.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\View\View
|
2016-02-21 06:15:37 +00:00
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function index(Request $request)
|
2016-02-21 06:15:37 +00:00
|
|
|
{
|
2017-07-01 20:29:49 +00:00
|
|
|
$users = $this->repository->search($request->input('query'))->getAllUsersWithCounts();
|
2017-03-03 23:14:21 +00:00
|
|
|
|
2016-02-21 06:15:37 +00:00
|
|
|
return view('admin.users.index', [
|
2017-07-01 20:29:49 +00:00
|
|
|
'users' => $users,
|
2016-02-21 06:15:37 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Display new user page.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-06-11 03:28:44 +00:00
|
|
|
public function create()
|
2016-02-21 06:15:37 +00:00
|
|
|
{
|
|
|
|
return view('admin.users.new');
|
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Display user view page.
|
|
|
|
*
|
2017-06-11 03:28:44 +00:00
|
|
|
* @param \Pterodactyl\Models\User $user
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-06-11 03:28:44 +00:00
|
|
|
public function view(User $user)
|
2016-02-21 06:15:37 +00:00
|
|
|
{
|
|
|
|
return view('admin.users.view', [
|
2017-06-11 03:28:44 +00:00
|
|
|
'user' => $user,
|
2016-02-21 06:15:37 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
2017-06-11 03:28:44 +00:00
|
|
|
* Delete a user from the system.
|
2017-03-19 23:36:50 +00:00
|
|
|
*
|
2017-06-25 00:49:09 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2017-06-11 03:28:44 +00:00
|
|
|
* @param \Pterodactyl\Models\User $user
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-06-14 04:25:37 +00:00
|
|
|
*
|
|
|
|
* @throws \Exception
|
2017-06-25 00:49:09 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2017-06-25 00:49:09 +00:00
|
|
|
public function delete(Request $request, User $user)
|
2016-02-21 06:15:37 +00:00
|
|
|
{
|
2017-06-25 00:49:09 +00:00
|
|
|
if ($request->user()->id === $user->id) {
|
|
|
|
throw new DisplayException('Cannot delete your own account.');
|
|
|
|
}
|
|
|
|
|
2016-02-21 06:15:37 +00:00
|
|
|
try {
|
2017-07-01 20:29:49 +00:00
|
|
|
$this->repository->deleteIfNoServers($user->id);
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-02-21 06:15:37 +00:00
|
|
|
return redirect()->route('admin.users');
|
2016-12-07 22:46:38 +00:00
|
|
|
} catch (DisplayException $ex) {
|
2017-06-14 04:25:37 +00:00
|
|
|
$this->alert->danger($ex->getMessage())->flash();
|
2016-02-21 06:15:37 +00:00
|
|
|
}
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-06-11 03:28:44 +00:00
|
|
|
return redirect()->route('admin.users.view', $user->id);
|
2016-02-21 06:15:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Create a user.
|
|
|
|
*
|
2017-06-11 03:28:44 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\UserFormRequest $request
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-06-14 04:25:37 +00:00
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
* @throws \Throwable
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2017-06-11 03:28:44 +00:00
|
|
|
public function store(UserFormRequest $request)
|
2016-02-21 06:15:37 +00:00
|
|
|
{
|
2017-06-14 04:25:37 +00:00
|
|
|
$user = $this->service->create($request->normalize());
|
2017-07-01 20:29:49 +00:00
|
|
|
|
2017-06-14 04:25:37 +00:00
|
|
|
$this->alert->success('Account has been successfully created.')->flash();
|
2017-06-11 03:28:44 +00:00
|
|
|
|
|
|
|
return redirect()->route('admin.users.view', $user->id);
|
2016-02-21 06:15:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
2017-06-11 03:28:44 +00:00
|
|
|
* Update a user on the system.
|
2017-03-19 23:36:50 +00:00
|
|
|
*
|
2017-06-25 00:49:09 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\UserFormRequest $request
|
|
|
|
* @param \Pterodactyl\Models\User $user
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-06-25 00:49:09 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2017-06-11 03:28:44 +00:00
|
|
|
public function update(UserFormRequest $request, User $user)
|
2016-02-21 06:15:37 +00:00
|
|
|
{
|
2017-06-17 22:36:39 +00:00
|
|
|
$this->service->update($user->id, $request->normalize());
|
2017-06-14 04:25:37 +00:00
|
|
|
$this->alert->success('User account has been updated.')->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-06-11 03:28:44 +00:00
|
|
|
return redirect()->route('admin.users.view', $user->id);
|
2016-02-21 06:15:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Get a JSON response of users on the system.
|
|
|
|
*
|
2017-07-22 18:55:30 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Database\Eloquent\Collection
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function json(Request $request)
|
2016-10-21 19:22:47 +00:00
|
|
|
{
|
2017-07-22 18:55:30 +00:00
|
|
|
return $this->repository->filterUsersByQuery($request->input('q'));
|
2016-10-21 19:22:47 +00:00
|
|
|
}
|
2016-02-21 06:15:37 +00:00
|
|
|
}
|