Merge branch 'development' of https://github.com/SahrulGnwn/controlpanel into development

This commit is contained in:
SahrulGnwn 2022-08-11 18:48:08 +07:00
commit 278ebb4130
7 changed files with 82 additions and 13 deletions

View file

@ -87,6 +87,33 @@ class Pterodactyl
if ($response->failed()) throw self::getException("Failed to get nodes from pterodactyl - ", $response->status()); if ($response->failed()) throw self::getException("Failed to get nodes from pterodactyl - ", $response->status());
return $response->json()['data']; return $response->json()['data'];
} }
/**
* @return mixed
* @throws Exception
* @description Returns the infos of a single node
*/
public static function getNode($id) {
try {
$response = self::client()->get('/application/nodes/' . $id);
} catch(Exception $e) {
throw self::getException($e->getMessage());
}
if($response->failed()) throw self::getException("Failed to get node id " . $id . " - " . $response->status());
return $response->json()['attributes'];
}
public static function getServers() {
try {
$response = self::client()->get('/application/servers');
} catch (Exception $e) {
throw self::getException($e->getMessage());
}
if($response->failed()) throw self::getException("Failed to get list of servers - ", $response->status());
return $response->json()['data'];
}
/** /**
* @return null * @return null

View file

@ -160,6 +160,17 @@ class UserController extends Controller
$user->delete(); $user->delete();
return redirect()->back()->with('success', __('user has been removed!')); return redirect()->back()->with('success', __('user has been removed!'));
} }
/**
* Verifys the users email
*
* @param User $user
* @return RedirectResponse
*/
public function verifyEmail(Request $request, User $user)
{
$user->verifyEmail();
return redirect()->back()->with('success', __('Email has been verified!'));
}
/** /**
* @param Request $request * @param Request $request
@ -285,6 +296,7 @@ class UserController extends Controller
$suspendText = $user->isSuspended() ? __("Unsuspend") : __("Suspend"); $suspendText = $user->isSuspended() ? __("Unsuspend") : __("Suspend");
return ' return '
<a data-content="' . __("Login as User") . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.loginas', $user->id) . '" class="btn btn-sm btn-primary mr-1"><i class="fas fa-sign-in-alt"></i></a> <a data-content="' . __("Login as User") . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.loginas', $user->id) . '" class="btn btn-sm btn-primary mr-1"><i class="fas fa-sign-in-alt"></i></a>
<a data-content="' . __("Verify") . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.verifyEmail', $user->id) . '" class="btn btn-sm btn-primary mr-1"><i class="fas fa-sign-in-alt"></i></a>
<a data-content="' . __("Show") . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.show', $user->id) . '" class="btn btn-sm text-white btn-warning mr-1"><i class="fas fa-eye"></i></a> <a data-content="' . __("Show") . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.show', $user->id) . '" class="btn btn-sm text-white btn-warning mr-1"><i class="fas fa-eye"></i></a>
<a data-content="' . __("Edit") . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.edit', $user->id) . '" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></a> <a data-content="' . __("Edit") . '" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.edit', $user->id) . '" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></a>
<form class="d-inline" method="post" action="' . route('admin.users.togglesuspend', $user->id) . '"> <form class="d-inline" method="post" action="' . route('admin.users.togglesuspend', $user->id) . '">

View file

@ -101,9 +101,31 @@ class ServerController extends Controller
return redirect()->route('servers.index')->with('error', __('Server limit reached!')); return redirect()->route('servers.index')->with('error', __('Server limit reached!'));
} }
// minimum credits // minimum credits && Check for Allocation
if (FacadesRequest::has("product")) { if (FacadesRequest::has("product")) {
$product = Product::findOrFail(FacadesRequest::input("product")); $product = Product::findOrFail(FacadesRequest::input("product"));
// Can we allocate the node? If not then error lol(I don't like overallocation)
$node = Pterodactyl::getNode(FacadesRequest::input('node'));
$nodeMem = $node['memory'];
$nodeDisk = $node['disk'];
$nodeName = $node['name'];
$currServers = Auth::user()->servers();
$currMem = 0;
$currDisk = 0;
foreach($currServers as $currServer) {
$pteroServer = $currServer->getPterodactylServer();
$psvAttr = $pteroServer['attributes'];
if($psvAttr['node'] != $node['id'])
continue;
$currMem += $psvAttr['limits']['memory'];
$currDisk += $psvAttr['limits']['disk'];
}
$currMem += $product->memory;
$currDisk += $product->disk;
if($currMem > $nodeMem || $currDisk > $nodeDisk)
return redirect()->route('servers.index')->with('error', "The node '" . $nodeName . "' doesn't have the required memory or disk left to allocate this product.");
// Min. Credits
if ( if (
Auth::user()->credits < Auth::user()->credits <
($product->minimum_credits == -1 ($product->minimum_credits == -1

View file

@ -259,4 +259,11 @@ class User extends Authenticatable implements MustVerifyEmail
$status = str_replace(' ', '/', $status); $status = str_replace(' ', '/', $status);
return $status; return $status;
} }
public function verifyEmail()
{
$this->forceFill([
'email_verified_at' => now(),
])->save();
}
} }

View file

@ -448,7 +448,7 @@ echo $cardheader;
?> ?>
<p class="login-box-msg">All done!</p> <p class="login-box-msg">All done!</p>
<p class="login-box-msg">You may navigate to your Dashboard now and log in!</p> <p class="login-box-msg">You may navigate to your Dashboard now and log in!</p>
<a href="<?php echo "https://" . $_SERVER['SERVER_NAME']; ?>"> <a href="<?php echo getEnvironmentValue("APP_URL"); ?>">
<button class="btn btn-success">Lets go!</button> <button class="btn btn-success">Lets go!</button>
</a> </a>
</div> </div>

View file

@ -224,39 +224,39 @@
<button type="button" data-toggle="modal" data-target="#UpgradeModal{{ $server->id }}" target="__blank" <button type="button" data-toggle="modal" data-target="#UpgradeModal{{ $server->id }}" target="__blank"
class="btn btn-info btn-md"> class="btn btn-info btn-md">
<i class="fas fa-upload mr-2"></i> <i class="fas fa-upload mr-2"></i>
<span>{{ __('Upgrade') }}</span> <span>{{ __('Upgrade / Downgrade') }}</span>
</button> </button>
<!-- Upgrade Modal --> <!-- Upgrade Modal -->
<div style="width: 100%; margin-block-start: 100px;" class="modal fade" id="UpgradeModal{{ $server->id }}" tabindex="-1"> <div style="width: 100%; margin-block-start: 100px;" class="modal fade" id="UpgradeModal{{ $server->id }}" tabindex="-1">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header card-header"> <div class="modal-header card-header">
<h5 class="modal-title">UPGRADE SERVER</h5> <h5 class="modal-title">{{__("Upgrade/Downgrade Server")}}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<div class="modal-body card-body"> <div class="modal-body card-body">
<strong>FOR DOWNGRADE PLEASE CHOOSE A PLAN BELOW YOUR PLAN</strong> <strong>{{__("FOR DOWNGRADE PLEASE CHOOSE A PLAN BELOW YOUR PLAN")}}</strong>
<br> <br>
<br> <br>
<strong>YOUR PRODUCT : </strong> {{ $server->product->name }} <strong>{{__("YOUR PRODUCT")}} : </strong> {{ $server->product->name }}
<br> <br>
<br> <br>
<form action="{{ route('servers.upgrade', ['server' => $server->id]) }}" method="POST"> <form action="{{ route('servers.upgrade', ['server' => $server->id]) }}" method="POST">
@csrf @csrf
<select name="product_upgrade" id="product_upgrade" class="form-input2 form-control"> <select name="product_upgrade" id="product_upgrade" class="form-input2 form-control">
<option value="">Select the product</option> <option value="">{{__("Select the product")}}</option>
@foreach($products as $product) @foreach($products as $product)
@if(in_array($server->egg, $product->eggs) && $product->id != $server->product->id) @if(in_array($server->egg, $product->eggs) && $product->id != $server->product->id)
<option value="{{ $product->id }}">{{ $product->name }} [ {{ CREDITS_DISPLAY_NAME }} {{ $product->price }} ]</option> <option value="{{ $product->id }}">{{ $product->name }} [ {{ CREDITS_DISPLAY_NAME }} {{ $product->price }} ]</option>
@endif @endif
@endforeach @endforeach
</select> </select>
<br> Once the Upgrade button is pressed, we will automatically deduct the amount for the first hour according to the new product from your credits. <br> <br> {{__("Once the Upgrade button is pressed, we will automatically deduct the amount for the first hour according to the new product from your credits")}}. <br>
</div> </div>
<div class="modal-footer card-body"> <div class="modal-footer card-body">
<button type="submit" class="btn btn-primary" style="width: 100%"><strong>Upgrade</strong></button> <button type="submit" class="btn btn-primary" style="width: 100%"><strong>{{__("Change Product")}}</strong></button>
</div> </div>
</form> </form>
</div> </div>
@ -273,20 +273,20 @@
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="DeleteModalLabel">Delete Server</h5> <h5 class="modal-title" id="DeleteModalLabel">{{__("Delete Server")}}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
This is an irreversible action, all files of this server will be removed.!!! {{__("This is an irreversible action, all files of this server will be removed!")}}
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<form class="d-inline" method="post" action="{{ route('servers.destroy', ['server' => $server->id]) }}"> <form class="d-inline" method="post" action="{{ route('servers.destroy', ['server' => $server->id]) }}">
@csrf @csrf
@method('DELETE') @method('DELETE')
<button data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-danger mr-1">Delete</button> <button data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-danger mr-1">{{__("Delete")}}</button>
</form> </form>
</div> </div>
</div> </div>
@ -305,4 +305,4 @@
<!-- END CONTENT --> <!-- END CONTENT -->
@endsection @endsection

View file

@ -115,6 +115,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
#users #users
Route::get("users.json", [UserController::class, "json"])->name('users.json'); Route::get("users.json", [UserController::class, "json"])->name('users.json');
Route::get('users/loginas/{user}', [UserController::class, 'loginAs'])->name('users.loginas'); Route::get('users/loginas/{user}', [UserController::class, 'loginAs'])->name('users.loginas');
Route::get('users/verifyEmail/{user}', [UserController::class, 'verifyEmail'])->name('users.verifyEmail');
Route::get('users/datatable', [UserController::class, 'datatable'])->name('users.datatable'); Route::get('users/datatable', [UserController::class, 'datatable'])->name('users.datatable');
Route::get('users/notifications', [UserController::class, 'notifications'])->name('users.notifications'); Route::get('users/notifications', [UserController::class, 'notifications'])->name('users.notifications');
Route::post('users/notifications', [UserController::class, 'notify'])->name('users.notifications'); Route::post('users/notifications', [UserController::class, 'notify'])->name('users.notifications');