From 255671e20da007c7f6a5fed7d2d53b16062a8b79 Mon Sep 17 00:00:00 2001 From: IceToast Date: Mon, 6 Feb 2023 14:45:44 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Merge=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ServerController.php | 50 ++- app/Models/User.php | 13 +- resources/views/servers/index.blade.php | 295 --------------- themes/default/views/servers/create.blade.php | 22 +- themes/default/views/servers/index.blade.php | 346 ++++++++++++------ 5 files changed, 280 insertions(+), 446 deletions(-) delete mode 100644 resources/views/servers/index.blade.php diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index 61ac4218..8822ad3a 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -33,7 +33,7 @@ class ServerController extends Controller //Get server infos from ptero $serverAttributes = Pterodactyl::getServerAttributes($server->pterodactyl_id, true); - if (! $serverAttributes) { + if (!$serverAttributes) { continue; } $serverRelationships = $serverAttributes['relationships']; @@ -70,7 +70,7 @@ class ServerController extends Controller /** Show the form for creating a new resource. */ public function create() { - if (! is_null($this->validateConfigurationRules())) { + if (!is_null($this->validateConfigurationRules())) { return $this->validateConfigurationRules(); } @@ -125,7 +125,7 @@ class ServerController extends Controller // Check if node has enough memory and disk space $checkResponse = Pterodactyl::checkNodeResources($node, $product->memory, $product->disk); if ($checkResponse == false) { - return redirect()->route('servers.index')->with('error', __("The node '".$nodeName."' doesn't have the required memory or disk left to allocate this product.")); + 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 @@ -133,23 +133,23 @@ class ServerController extends Controller Auth::user()->credits < $product->minimum_credits || Auth::user()->credits < $product->price ) { - return redirect()->route('servers.index')->with('error', 'You do not have the required amount of '.CREDITS_DISPLAY_NAME.' to use this product!'); + return redirect()->route('servers.index')->with('error', 'You do not have the required amount of ' . CREDITS_DISPLAY_NAME . ' to use this product!'); } } //Required Verification for creating an server - if (config('SETTINGS::USER:FORCE_EMAIL_VERIFICATION', 'false') === 'true' && ! Auth::user()->hasVerifiedEmail()) { + if (config('SETTINGS::USER:FORCE_EMAIL_VERIFICATION', 'false') === 'true' && !Auth::user()->hasVerifiedEmail()) { return redirect()->route('profile.index')->with('error', __('You are required to verify your email address before you can create a server.')); } //Required Verification for creating an server - if (! config('SETTINGS::SYSTEM:CREATION_OF_NEW_SERVERS', 'true') && Auth::user()->role != 'admin') { + if (!config('SETTINGS::SYSTEM:CREATION_OF_NEW_SERVERS', 'true') && Auth::user()->role != 'admin') { return redirect()->route('servers.index')->with('error', __('The system administrator has blocked the creation of new servers.')); } //Required Verification for creating an server - if (config('SETTINGS::USER:FORCE_DISCORD_VERIFICATION', 'false') === 'true' && ! Auth::user()->discordUser) { + if (config('SETTINGS::USER:FORCE_DISCORD_VERIFICATION', 'false') === 'true' && !Auth::user()->discordUser) { return redirect()->route('profile.index')->with('error', __('You are required to link your discord account before you can create a server.')); } @@ -162,7 +162,7 @@ class ServerController extends Controller /** @var Node $node */ /** @var Egg $egg */ /** @var Product $product */ - if (! is_null($this->validateConfigurationRules())) { + if (!is_null($this->validateConfigurationRules())) { return $this->validateConfigurationRules(); } @@ -186,7 +186,7 @@ class ServerController extends Controller //get free allocation ID $allocationId = Pterodactyl::getFreeAllocationId($node); - if (! $allocationId) { + if (!$allocationId) { return $this->noAllocationsError($server); } @@ -249,13 +249,9 @@ class ServerController extends Controller } /** Cancel Server */ - public function cancel (Server $server) + public function cancel(Server $server) { try { - error_log($server->update([ - 'cancelled' => now(), - ])); - return redirect()->route('servers.index')->with('success', __('Server cancelled')); } catch (Exception $e) { return redirect()->route('servers.index')->with('error', __('An exception has occurred while trying to cancel the server"') . $e->getMessage() . '"'); @@ -267,7 +263,9 @@ class ServerController extends Controller { - if($server->user_id != Auth::user()->id){ return back()->with('error', __('This is not your Server!'));} + if ($server->user_id != Auth::user()->id) { + return back()->with('error', __('This is not your Server!')); + } $serverAttributes = Pterodactyl::getServerAttributes($server->pterodactyl_id); $serverRelationships = $serverAttributes['relationships']; $serverLocationAttributes = $serverRelationships['location']['attributes']; @@ -287,10 +285,10 @@ class ServerController extends Controller $pteroNode = Pterodactyl::getNode($serverRelationships['node']['attributes']['id']); $products = Product::orderBy('created_at') - ->whereHas('nodes', function (Builder $builder) use ($serverRelationships) { //Only show products for that node - $builder->where('id', '=', $serverRelationships['node']['attributes']['id']); - }) - ->get(); + ->whereHas('nodes', function (Builder $builder) use ($serverRelationships) { //Only show products for that node + $builder->where('id', '=', $serverRelationships['node']['attributes']['id']); + }) + ->get(); // Set the each product eggs array to just contain the eggs name foreach ($products as $product) { @@ -308,9 +306,8 @@ class ServerController extends Controller public function upgrade(Server $server, Request $request) { - if($server->user_id != Auth::user()->id || $server->suspended) return redirect()->route('servers.index'); - if(!isset($request->product_upgrade)) - { + if ($server->user_id != Auth::user()->id || $server->suspended) return redirect()->route('servers.index'); + if (!isset($request->product_upgrade)) { return redirect()->route('servers.show', ['server' => $server->id])->with('error', __('this product is the only one')); } $user = Auth::user(); @@ -329,7 +326,7 @@ class ServerController extends Controller $requiredisk = $newProduct->disk - $oldProduct->disk; $checkResponse = Pterodactyl::checkNodeResources($node, $requireMemory, $requiredisk); if ($checkResponse == false) { - return redirect()->route('servers.index')->with('error', __("The node '".$nodeName."' doesn't have the required memory or disk left to upgrade the server.")); + return redirect()->route('servers.index')->with('error', __("The node '" . $nodeName . "' doesn't have the required memory or disk left to upgrade the server.")); } // calculate the amount of credits that the user overpayed for the old product when canceling the server right now @@ -353,8 +350,7 @@ class ServerController extends Controller $overpayedCredits = $oldProduct->price - $oldProduct->price * ($timeDifference / $billingPeriodMultiplier); - if ($user->credits >= $newProduct->price && $user->credits >= $newProduct->minimum_credits) - { + if ($user->credits >= $newProduct->price && $user->credits >= $newProduct->minimum_credits) { $server->allocation = $serverAttributes['allocation']; // Update the server on the panel $response = Pterodactyl::updateServer($server, $newProduct); @@ -374,11 +370,11 @@ class ServerController extends Controller if ($overpayedCredits > 0) $user->increment('credits', $overpayedCredits); // Withdraw the credits for the new product - $user->decrement('credits', $newProduct->price); + $user->decrement('credits', $newProduct->price); //restart the server $response = Pterodactyl::powerAction($server, "restart"); - if ($response->failed()) return redirect()->route('servers.index')->with('error', 'Server upgraded successfully! Could not restart the server: '.$response->json()['errors'][0]['detail']); + if ($response->failed()) return redirect()->route('servers.index')->with('error', 'Server upgraded successfully! Could not restart the server: ' . $response->json()['errors'][0]['detail']); return redirect()->route('servers.show', ['server' => $server->id])->with('success', __('Server Successfully Upgraded')); } else { return redirect()->route('servers.show', ['server' => $server->id])->with('error', __('Not Enough Balance for Upgrade')); diff --git a/app/Models/User.php b/app/Models/User.php index 91e15cab..199bb25d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -185,7 +185,7 @@ class User extends Authenticatable implements MustVerifyEmail } /** - * @throws Exception + * @throws \Exception */ public function suspend() { @@ -201,7 +201,7 @@ class User extends Authenticatable implements MustVerifyEmail } /** - * @throws Exception + * @throws \Exception */ public function unSuspend() { @@ -218,12 +218,6 @@ class User extends Authenticatable implements MustVerifyEmail return $this; } - private function getServersWithProduct() - { - return $this->servers() - ->with('product') - ->get(); - } /** * @return string @@ -257,7 +251,8 @@ class User extends Authenticatable implements MustVerifyEmail return number_format($usage, 2, '.', ''); } - private function getServersWithProduct() { + private function getServersWithProduct() + { return $this->servers() ->whereNull('suspended') ->whereNull('cancelled') diff --git a/resources/views/servers/index.blade.php b/resources/views/servers/index.blade.php deleted file mode 100644 index 7910a30a..00000000 --- a/resources/views/servers/index.blade.php +++ /dev/null @@ -1,295 +0,0 @@ -@extends('layouts.main') - -@section('content') - -
-
-
-
-

{{ __('Servers') }}

-
- -
-
-
- - - -
-
- - - - -
- @foreach ($servers as $server) -
-
-
-
{{ $server->name }} -
-
- -
-
-
-
-
-
-
{{ __('Status') }}:
-
- @if($server->suspended) - {{ __('Suspended') }} - @elseif($server->cancelled) - {{ __('Cancelled') }} - @else - {{ __('Active') }} - @endif -
-
-
-
- {{ __('Location') }}: -
-
- {{ $server->location }} - -
- -
-
-
- {{ __('Software') }}: -
-
- {{ $server->nest }} -
- -
-
-
- {{ __('Specification') }}: -
-
- {{ $server->egg }} -
-
-
-
- {{ __('Resource plan') }}: -
-
- {{ $server->product->name }} - - -
-
- -
-
- {{ __('Next Billing Cycle') }}: -
-
- - @if ($server->suspended) - - - @else - @switch($server->product->billing_period) - @case('monthly') - {{ \Carbon\Carbon::parse($server->last_billed)->addMonth()->toDayDateTimeString(); }} - @break - @case('weekly') - {{ \Carbon\Carbon::parse($server->last_billed)->addWeek()->toDayDateTimeString(); }} - @break - @case('daily') - {{ \Carbon\Carbon::parse($server->last_billed)->addDay()->toDayDateTimeString(); }} - @break - @case('hourly') - {{ \Carbon\Carbon::parse($server->last_billed)->addHour()->toDayDateTimeString(); }} - @break - @case('quarterly') - {{ \Carbon\Carbon::parse($server->last_billed)->addMonths(3)->toDayDateTimeString(); }} - @break - @case('half-annually') - {{ \Carbon\Carbon::parse($server->last_billed)->addMonths(6)->toDayDateTimeString(); }} - @break - @case('annually') - {{ \Carbon\Carbon::parse($server->last_billed)->addYear()->toDayDateTimeString(); }} - @break - @default - {{ __('Unknown') }} - @endswitch - @endif - -
-
- -
-
- {{ __('Price') }}: - - ({{ CREDITS_DISPLAY_NAME }}) - -
-
-
- @if($server->product->billing_period == 'monthly') - {{ __('per Month') }} - @elseif($server->product->billing_period == 'half-annually') - {{ __('per 6 Months') }} - @elseif($server->product->billing_period == 'quarterly') - {{ __('per 3 Months') }} - @elseif($server->product->billing_period == 'annually') - {{ __('per Year') }} - @elseif($server->product->billing_period == 'weekly') - {{ __('per Week') }} - @elseif($server->product->billing_period == 'daily') - {{ __('per Day') }} - @elseif($server->product->billing_period == 'hourly') - {{ __('per Hour') }} - @endif -
- - {{ $server->product->price == round($server->product->price) ? round($server->product->price) : $server->product->price }} - -
-
-
-
- - -
- @endforeach -
- -
-
- - - -@endsection diff --git a/themes/default/views/servers/create.blade.php b/themes/default/views/servers/create.blade.php index 0a91cc04..ec18ebfe 100644 --- a/themes/default/views/servers/create.blade.php +++ b/themes/default/views/servers/create.blade.php @@ -213,11 +213,11 @@ -
  • +
  • {{ __('Minimum') }} {{ CREDITS_DISPLAY_NAME }} + x-text="product.minimum_credits == -1 ? {{ config('SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER') }} : Math.round(product.minimum_credits)">
  • @@ -240,14 +240,16 @@
    - +
    diff --git a/themes/default/views/servers/index.blade.php b/themes/default/views/servers/index.blade.php index ef856b6a..7910a30a 100644 --- a/themes/default/views/servers/index.blade.php +++ b/themes/default/views/servers/index.blade.php @@ -36,124 +36,260 @@ class="fa fa-plus mr-2"> {{ __('Create Server') }} - @if (Auth::user()->Servers->count() > 0&&!empty(config('SETTINGS::MISC:PHPMYADMIN:URL'))) - {{ __('Database') }} - - @endif
    @foreach ($servers as $server) - @if($server->location&&$server->node&&$server->nest&&$server->egg) -
    -
    -
    -
    {{ $server->name }} -
    -
    -
    -
    -
    -
    -
    {{ __('Status') }}:
    -
    - - {{ $server->isSuspended() ? 'Suspended' : 'Active' }} -
    -
    -
    -
    - {{ __('Location') }}: -
    -
    - {{ $server->location }} - -
    - -
    -
    -
    - {{ __('Software') }}: -
    -
    - {{ $server->nest }} -
    - -
    -
    -
    - {{ __('Specification') }}: -
    -
    - {{ $server->egg }} -
    -
    -
    -
    - {{ __('Resource plan') }}: -
    -
    - {{ $server->product->name }} - - -
    - -
    -
    -
    - {{ __('Price') }}: - - ({{ CREDITS_DISPLAY_NAME }}) - -
    -
    -
    -
    -
    {{ __('per Hour') }}
    - - {{ number_format($server->product->getHourlyPrice(), 2, '.', '') }} - -
    -
    -
    {{ __('per Month') }} -
    - - {{ $server->product->getHourlyPrice() * 24 * 30 }} - -
    -
    +
    +
    +
    +
    {{ $server->name }} +
    +
    +
    - -
    - @endif +
    +
    +
    +
    {{ __('Status') }}:
    +
    + @if($server->suspended) + {{ __('Suspended') }} + @elseif($server->cancelled) + {{ __('Cancelled') }} + @else + {{ __('Active') }} + @endif +
    +
    +
    +
    + {{ __('Location') }}: +
    +
    + {{ $server->location }} + +
    + +
    +
    +
    + {{ __('Software') }}: +
    +
    + {{ $server->nest }} +
    + +
    +
    +
    + {{ __('Specification') }}: +
    +
    + {{ $server->egg }} +
    +
    +
    +
    + {{ __('Resource plan') }}: +
    +
    + {{ $server->product->name }} + + +
    +
    + +
    +
    + {{ __('Next Billing Cycle') }}: +
    +
    + + @if ($server->suspended) + - + @else + @switch($server->product->billing_period) + @case('monthly') + {{ \Carbon\Carbon::parse($server->last_billed)->addMonth()->toDayDateTimeString(); }} + @break + @case('weekly') + {{ \Carbon\Carbon::parse($server->last_billed)->addWeek()->toDayDateTimeString(); }} + @break + @case('daily') + {{ \Carbon\Carbon::parse($server->last_billed)->addDay()->toDayDateTimeString(); }} + @break + @case('hourly') + {{ \Carbon\Carbon::parse($server->last_billed)->addHour()->toDayDateTimeString(); }} + @break + @case('quarterly') + {{ \Carbon\Carbon::parse($server->last_billed)->addMonths(3)->toDayDateTimeString(); }} + @break + @case('half-annually') + {{ \Carbon\Carbon::parse($server->last_billed)->addMonths(6)->toDayDateTimeString(); }} + @break + @case('annually') + {{ \Carbon\Carbon::parse($server->last_billed)->addYear()->toDayDateTimeString(); }} + @break + @default + {{ __('Unknown') }} + @endswitch + @endif + +
    +
    + +
    +
    + {{ __('Price') }}: + + ({{ CREDITS_DISPLAY_NAME }}) + +
    +
    +
    + @if($server->product->billing_period == 'monthly') + {{ __('per Month') }} + @elseif($server->product->billing_period == 'half-annually') + {{ __('per 6 Months') }} + @elseif($server->product->billing_period == 'quarterly') + {{ __('per 3 Months') }} + @elseif($server->product->billing_period == 'annually') + {{ __('per Year') }} + @elseif($server->product->billing_period == 'weekly') + {{ __('per Week') }} + @elseif($server->product->billing_period == 'daily') + {{ __('per Day') }} + @elseif($server->product->billing_period == 'hourly') + {{ __('per Hour') }} + @endif +
    + + {{ $server->product->price == round($server->product->price) ? round($server->product->price) : $server->product->price }} + +
    +
    +
    +
    + + +
    @endforeach
    + + @endsection