2016-02-21 06:15:37 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
2017-01-24 22:57:08 +00:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>
|
2016-12-07 22:46:38 +00:00
|
|
|
* Some Modifications (c) 2015 Dylan Seidt <dylan.seidt@gmail.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;
|
|
|
|
|
|
|
|
use Log;
|
2016-12-07 22:46:38 +00:00
|
|
|
use Alert;
|
|
|
|
use Illuminate\Http\Request;
|
2016-02-21 06:15:37 +00:00
|
|
|
use Pterodactyl\Models\User;
|
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2016-12-07 22:46:38 +00:00
|
|
|
use Pterodactyl\Repositories\UserRepository;
|
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException;
|
2016-02-21 06:15:37 +00:00
|
|
|
|
|
|
|
class UserController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
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-04-14 03:49:47 +00:00
|
|
|
$users = User::withCount('servers', 'subuserOf');
|
2017-03-03 23:14:21 +00:00
|
|
|
|
|
|
|
if (! is_null($request->input('query'))) {
|
|
|
|
$users->search($request->input('query'));
|
|
|
|
}
|
|
|
|
|
2016-02-21 06:15:37 +00:00
|
|
|
return view('admin.users.index', [
|
2017-03-03 23:14:21 +00:00
|
|
|
'users' => $users->paginate(25),
|
2016-02-21 06:15:37 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Display new user page.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function create(Request $request)
|
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.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function view(Request $request, $id)
|
2016-02-21 06:15:37 +00:00
|
|
|
{
|
|
|
|
return view('admin.users.view', [
|
2017-02-09 22:43:54 +00:00
|
|
|
'user' => User::with('servers.node')->findOrFail($id),
|
2016-02-21 06:15:37 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Delete a user.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function delete(Request $request, $id)
|
2016-02-21 06:15:37 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$repo = new UserRepository;
|
|
|
|
$repo->delete($id);
|
|
|
|
Alert::success('Successfully deleted user from system.')->flash();
|
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) {
|
2016-02-21 06:15:37 +00:00
|
|
|
Alert::danger($ex->getMessage())->flash();
|
|
|
|
} catch (\Exception $ex) {
|
|
|
|
Log::error($ex);
|
|
|
|
Alert::danger('An exception was encountered while attempting to delete this user.')->flash();
|
|
|
|
}
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-02-21 06:15:37 +00:00
|
|
|
return redirect()->route('admin.users.view', $id);
|
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Create a user.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function store(Request $request)
|
2016-02-21 06:15:37 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$user = new UserRepository;
|
2017-01-12 20:40:24 +00:00
|
|
|
$userid = $user->create($request->only([
|
2017-02-10 22:18:46 +00:00
|
|
|
'email', 'password', 'name_first',
|
|
|
|
'name_last', 'username', 'root_admin',
|
2017-01-12 20:40:24 +00:00
|
|
|
]));
|
2016-02-21 06:15:37 +00:00
|
|
|
Alert::success('Account has been successfully created.')->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-02-21 06:15:37 +00:00
|
|
|
return redirect()->route('admin.users.view', $userid);
|
|
|
|
} 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();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-02-21 06:15:37 +00:00
|
|
|
return redirect()->route('admin.users.new');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Update a user.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2017-04-09 19:31:10 +00:00
|
|
|
* @param int $id
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function update(Request $request, $id)
|
2016-02-21 06:15:37 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$repo = new UserRepository;
|
2017-04-14 02:30:32 +00:00
|
|
|
$user = $repo->update($id, $request->intersect([
|
2017-02-10 22:18:46 +00:00
|
|
|
'email', 'password', 'name_first',
|
|
|
|
'name_last', 'username', 'root_admin',
|
2017-01-12 20:40:24 +00:00
|
|
|
]));
|
2016-02-21 06:15:37 +00:00
|
|
|
Alert::success('User account was successfully updated.')->flash();
|
|
|
|
} catch (DisplayValidationException $ex) {
|
2017-04-09 19:31:10 +00:00
|
|
|
return redirect()->route('admin.users.view', $id)->withErrors(json_decode($ex->getMessage()));
|
|
|
|
} catch (\Exception $ex) {
|
|
|
|
Log::error($ex);
|
2016-02-21 06:15:37 +00:00
|
|
|
Alert::danger('An error occured while attempting to update this user.')->flash();
|
|
|
|
}
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-04-09 19:31:10 +00:00
|
|
|
return redirect()->route('admin.users.view', $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.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Pterodactyl\Models\User
|
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function json(Request $request)
|
2016-10-21 19:22:47 +00:00
|
|
|
{
|
2017-02-19 00:31:44 +00:00
|
|
|
return User::select('id', 'email', 'username', 'name_first', 'name_last')
|
|
|
|
->search($request->input('q'))
|
|
|
|
->get()->transform(function ($item) {
|
|
|
|
$item->md5 = md5(strtolower($item->email));
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
});
|
2016-10-21 19:22:47 +00:00
|
|
|
}
|
2016-02-21 06:15:37 +00:00
|
|
|
}
|