2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
2016-01-20 00:10:39 +00:00
|
|
|
/**
|
|
|
|
* Pterodactyl Panel
|
|
|
|
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2015-12-06 18:58:49 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
2015-12-12 06:21:17 +00:00
|
|
|
use Alert;
|
2016-01-02 05:25:41 +00:00
|
|
|
use Mail;
|
2016-01-02 20:08:33 +00:00
|
|
|
use Log;
|
2015-12-12 06:21:17 +00:00
|
|
|
use Pterodactyl\Models\User;
|
2015-12-14 03:22:16 +00:00
|
|
|
use Pterodactyl\Repositories\UserRepository;
|
2016-01-02 05:25:41 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
2015-12-14 03:22:16 +00:00
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class AccountsController extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller Constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2016-01-04 21:09:39 +00:00
|
|
|
//
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getIndex(Request $request)
|
|
|
|
{
|
|
|
|
return view('admin.accounts.index', [
|
|
|
|
'users' => User::paginate(20)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getNew(Request $request)
|
|
|
|
{
|
2015-12-12 06:21:17 +00:00
|
|
|
return view('admin.accounts.new');
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getView(Request $request, $id)
|
|
|
|
{
|
2016-01-02 20:08:33 +00:00
|
|
|
return view('admin.accounts.view', [
|
|
|
|
'user' => User::findOrFail($id),
|
|
|
|
'servers' => Server::select('servers.*', 'nodes.name as nodeName', 'locations.long as location')
|
|
|
|
->join('nodes', 'servers.node', '=', 'nodes.id')
|
|
|
|
->join('locations', 'nodes.location', '=', 'locations.id')
|
|
|
|
->where('active', 1)
|
|
|
|
->get(),
|
|
|
|
]);
|
2016-01-02 05:25:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 21:22:57 +00:00
|
|
|
public function deleteView(Request $request, $id)
|
2016-01-02 05:25:41 +00:00
|
|
|
{
|
2016-01-04 21:22:57 +00:00
|
|
|
try {
|
|
|
|
User::findOrFail($id)->delete();
|
|
|
|
return response(null, 204);
|
|
|
|
} catch(\Exception $ex) {
|
|
|
|
Log::error($ex);
|
|
|
|
return response()->json([
|
|
|
|
'error' => 'An error occured while attempting to delete this user.'
|
|
|
|
], 500);
|
|
|
|
}
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-12 06:21:17 +00:00
|
|
|
public function postNew(Request $request)
|
|
|
|
{
|
2015-12-14 03:22:16 +00:00
|
|
|
try {
|
|
|
|
$user = new UserRepository;
|
|
|
|
$userid = $user->create($request->input('username'), $request->input('email'), $request->input('password'));
|
|
|
|
Alert::success('Account has been successfully created.')->flash();
|
|
|
|
return redirect()->route('admin.accounts.view', ['id' => $userid]);
|
2016-01-13 04:43:33 +00:00
|
|
|
} catch (\Pterodactyl\Exceptions\DisplayValidationException $ex) {
|
|
|
|
return redirect()->route('admin.nodes.view', $id)->withErrors(json_decode($e->getMessage()))->withInput();
|
|
|
|
} catch (\Exception $ex) {
|
|
|
|
Log::error($ex);
|
2016-01-02 20:08:33 +00:00
|
|
|
Alert::danger('An error occured while attempting to add a new user. ' . $e->getMessage())->flash();
|
2015-12-14 03:22:16 +00:00
|
|
|
return redirect()->route('admin.accounts.new');
|
|
|
|
}
|
2015-12-12 06:21:17 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 05:25:41 +00:00
|
|
|
public function postUpdate(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'email' => 'required|email|unique:users,email,'.$request->input('user'),
|
|
|
|
'root_admin' => 'required',
|
2016-01-02 20:08:33 +00:00
|
|
|
'password' => 'required_with:password_confirmation|confirmed',
|
2016-01-02 05:25:41 +00:00
|
|
|
'password_confirmation' => 'required_with:password'
|
|
|
|
]);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$users = new UserRepository;
|
2016-01-02 20:08:33 +00:00
|
|
|
$user = [
|
|
|
|
'email' => $request->input('email'),
|
|
|
|
'root_admin' => $request->input('root_admin')
|
|
|
|
];
|
2016-01-02 05:25:41 +00:00
|
|
|
|
|
|
|
if(!empty($request->input('password'))) {
|
|
|
|
$user['password'] = $request->input('password');
|
|
|
|
}
|
|
|
|
|
2016-01-02 20:08:33 +00:00
|
|
|
if(!$users->update($request->input('user'), $user)) {
|
|
|
|
throw new \Exception('Unable to update user, response was not valid.');
|
|
|
|
}
|
2016-01-02 05:25:41 +00:00
|
|
|
|
2016-01-02 20:08:33 +00:00
|
|
|
if($request->input('email_user')) {
|
|
|
|
Mail::send('emails.new_password', ['user' => User::findOrFail($request->input('user')), 'password' => $request->input('password')], function($message) use ($request) {
|
|
|
|
$message->to($request->input('email'))->subject('Pterodactyl - Admin Reset Password');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Alert::success('User account was successfully updated.')->flash();
|
2016-01-02 05:25:41 +00:00
|
|
|
return redirect()->route('admin.accounts.view', ['id' => $request->input('user')]);
|
|
|
|
|
2016-01-02 20:08:33 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error($e);
|
|
|
|
Alert::danger('An error occured while attempting to update this user. ' . $e->getMessage())->flash();
|
|
|
|
return redirect()->route('admin.accounts.view', ['id' => $request->input('user')]);
|
2016-01-02 05:25:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|