Model fixing, moving things around to improve code.
Adds unique UUID generator, moves functions into repositories for adding servers and users, cleans up code, adding more comments.
This commit is contained in:
parent
01eaeaf178
commit
22b0bbf6ce
8 changed files with 333 additions and 250 deletions
|
@ -3,11 +3,9 @@
|
|||
namespace Pterodactyl\Http\Controllers\Admin;
|
||||
|
||||
use Alert;
|
||||
use Debugbar;
|
||||
use Hash;
|
||||
use Uuid;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Repositories\UserRepository;
|
||||
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
@ -52,18 +50,19 @@ class AccountsController extends Controller
|
|||
'password_confirmation' => 'required'
|
||||
]);
|
||||
|
||||
//@TODO: re-generate UUID if conflict
|
||||
$user = new User;
|
||||
$user->uuid = Uuid::generate(4);
|
||||
try {
|
||||
|
||||
$user->username = $request->input('username');
|
||||
$user->email = $request->input('email');
|
||||
$user->password = Hash::make($request->input('password'));
|
||||
$user = new UserRepository;
|
||||
$userid = $user->create($request->input('username'), $request->input('email'), $request->input('password'));
|
||||
|
||||
$user->save();
|
||||
Alert::success('Account has been successfully created.')->flash();
|
||||
return redirect()->route('admin.accounts.view', ['id' => $userid]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Alert::danger('An error occured while attempting to add a new user. Please check the logs or try again.')->flash();
|
||||
return redirect()->route('admin.accounts.new');
|
||||
}
|
||||
|
||||
Alert::success('Account has been successfully created.')->flash();
|
||||
return redirect()->route('admin.accounts.view', ['id' => $user->id]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Http\Controllers\Admin;
|
||||
|
||||
use Debugbar;
|
||||
use Pterodactyl\Repositories\ServerRepository;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Location;
|
||||
|
@ -56,7 +57,8 @@ class ServersController extends Controller
|
|||
{
|
||||
|
||||
try {
|
||||
$resp = Server::addServer($request->all());
|
||||
$server = new ServerRepository;
|
||||
$resp = $server->create($request->all());
|
||||
echo $resp . '<br />';
|
||||
} catch (\Exception $e) {
|
||||
Debugbar::addException($e);
|
||||
|
|
|
@ -3,14 +3,12 @@
|
|||
namespace Pterodactyl\Http\Controllers\Base;
|
||||
|
||||
use Auth;
|
||||
use Debugbar;
|
||||
use Hash;
|
||||
use Google2FA;
|
||||
use Log;
|
||||
use Alert;
|
||||
use Pterodactyl\Exceptions\AccountNotFoundException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Models\User;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
@ -74,22 +72,18 @@ class IndexController extends Controller
|
|||
public function putAccountTotp(Request $request)
|
||||
{
|
||||
|
||||
try {
|
||||
$totpSecret = User::setTotpSecret(Auth::user()->id);
|
||||
} catch (\Exception $e) {
|
||||
if ($e instanceof AccountNotFoundException) {
|
||||
return response($e->getMessage(), 500);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
$user = $request->user();
|
||||
|
||||
$user->totp_secret = Google2FA::generateSecretKey();
|
||||
$user->save();
|
||||
|
||||
return response()->json([
|
||||
'qrImage' => Google2FA::getQRCodeGoogleUrl(
|
||||
'Pterodactyl',
|
||||
Auth::user()->email,
|
||||
$totpSecret
|
||||
$user->email,
|
||||
$user->totp_secret
|
||||
),
|
||||
'secret' => $totpSecret
|
||||
'secret' => $user->totp_secret
|
||||
]);
|
||||
|
||||
}
|
||||
|
@ -104,21 +98,16 @@ class IndexController extends Controller
|
|||
{
|
||||
|
||||
if (!$request->has('token')) {
|
||||
return response('No input \'token\' defined.', 500);
|
||||
return response(null, 500);
|
||||
}
|
||||
|
||||
try {
|
||||
if(User::toggleTotp(Auth::user()->id, $request->input('token'))) {
|
||||
return response('true');
|
||||
}
|
||||
return response('false');
|
||||
} catch (\Exception $e) {
|
||||
if ($e instanceof AccountNotFoundException) {
|
||||
return response($e->getMessage(), 500);
|
||||
}
|
||||
throw $e;
|
||||
$user = $request->user();
|
||||
if($user->toggleTotp($request->input('token'))) {
|
||||
return response('true');
|
||||
}
|
||||
|
||||
return response('false');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,21 +124,14 @@ class IndexController extends Controller
|
|||
return redirect()->route('account.totp');
|
||||
}
|
||||
|
||||
try {
|
||||
if(User::toggleTotp(Auth::user()->id, $request->input('token'))) {
|
||||
return redirect()->route('account.totp');
|
||||
}
|
||||
|
||||
Alert::danger('Unable to disable TOTP on this account, was the token correct?')->flash();
|
||||
$user = $request->user();
|
||||
if($user->toggleTotp($request->input('token'))) {
|
||||
return redirect()->route('account.totp');
|
||||
} catch (\Exception $e) {
|
||||
if ($e instanceof AccountNotFoundException) {
|
||||
Alert::danger('An error occured while attempting to perform this action.')->flash();
|
||||
return redirect()->route('account.totp');
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
Alert::danger('The TOTP token provided was invalid.')->flash();
|
||||
return redirect()->route('account.totp');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,23 +159,19 @@ class IndexController extends Controller
|
|||
'password' => 'required'
|
||||
]);
|
||||
|
||||
if (!password_verify($request->input('password'), Auth::user()->password)) {
|
||||
$user = $request->user();
|
||||
|
||||
if (!password_verify($request->input('password'), $user->password)) {
|
||||
Alert::danger('The password provided was not valid for this account.')->flash();
|
||||
return redirect()->route('account');
|
||||
}
|
||||
|
||||
// Met Validation, lets roll out.
|
||||
try {
|
||||
User::setEmail(Auth::user()->id, $request->input('new_email'));
|
||||
Alert::success('Your email address has successfully been updated.')->flash();
|
||||
return redirect()->route('account');
|
||||
} catch (\Exception $e) {
|
||||
if ($e instanceof AccountNotFoundException || $e instanceof DisplayException) {
|
||||
Alert::danger($e->getMessage())->flash();
|
||||
return redirect()->route('account');
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
$user->email = $request->input('new_email');
|
||||
$user->save();
|
||||
|
||||
Alert::success('Your email address has successfully been updated.')->flash();
|
||||
return redirect()->route('account');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,24 +189,22 @@ class IndexController extends Controller
|
|||
'new_password_confirmation' => 'required'
|
||||
]);
|
||||
|
||||
if (!password_verify($request->input('current_password'), Auth::user()->password)) {
|
||||
$user = $request->user();
|
||||
|
||||
if (!password_verify($request->input('current_password'), $user->password)) {
|
||||
Alert::danger('The password provided was not valid for this account.')->flash();
|
||||
return redirect()->route('account');
|
||||
}
|
||||
|
||||
// Met Validation, lets roll out.
|
||||
try {
|
||||
User::setPassword(Auth::user()->id, $request->input('new_password'));
|
||||
$user->setPassword($request->input('new_password'));
|
||||
Alert::success('Your password has successfully been updated.')->flash();
|
||||
return redirect()->route('account');
|
||||
} catch (\Exception $e) {
|
||||
if ($e instanceof AccountNotFoundException || $e instanceof DisplayException) {
|
||||
Alert::danger($e->getMessage())->flash();
|
||||
return redirect()->route('account');
|
||||
}
|
||||
throw $e;
|
||||
} catch (DisplayException $e) {
|
||||
Alert::danger($e->getMessage())->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('account');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue