update auto unsuspend servers to be server resource friendlier
This commit is contained in:
parent
b8c8cb7404
commit
5877ddbe81
|
@ -11,7 +11,7 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
use Illuminate\Foundation\Events\Dispatchable;
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class UserUpdatedEvent
|
class UserUpdateCreditsEvent
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Events\UserUpdateCreditsEvent;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Configuration;
|
use App\Models\Configuration;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
|
@ -167,6 +168,8 @@ class PaymentController extends Controller
|
||||||
//payment notification
|
//payment notification
|
||||||
$user->notify(new ConfirmPaymentNotification($payment));
|
$user->notify(new ConfirmPaymentNotification($payment));
|
||||||
|
|
||||||
|
event(new UserUpdateCreditsEvent($user));
|
||||||
|
|
||||||
//redirect back to home
|
//redirect back to home
|
||||||
return redirect()->route('home')->with('success', 'Your credit balance has been increased!');
|
return redirect()->route('home')->with('success', 'Your credit balance has been increased!');
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Classes\Pterodactyl;
|
use App\Classes\Pterodactyl;
|
||||||
|
use App\Events\UserUpdateCreditsEvent;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\DynamicNotification;
|
use App\Notifications\DynamicNotification;
|
||||||
|
@ -130,6 +131,7 @@ class UserController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->update($request->all());
|
$user->update($request->all());
|
||||||
|
event(new UserUpdateCreditsEvent($user));
|
||||||
|
|
||||||
return redirect()->route('admin.users.index')->with('success', 'User updated!');
|
return redirect()->route('admin.users.index')->with('success', 'User updated!');
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Events\UserUpdateCreditsEvent;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Voucher;
|
use App\Models\Voucher;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
|
@ -149,6 +150,8 @@ class VoucherController extends Controller
|
||||||
#redeem voucher
|
#redeem voucher
|
||||||
$voucher->redeem($request->user());
|
$voucher->redeem($request->user());
|
||||||
|
|
||||||
|
event(new UserUpdateCreditsEvent($request->user()));
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => "{$voucher->credits} ".CREDITS_DISPLAY_NAME." have been added to your balance!"
|
'success' => "{$voucher->credits} ".CREDITS_DISPLAY_NAME." have been added to your balance!"
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Events\UserUpdateCreditsEvent;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\DiscordUser;
|
use App\Models\DiscordUser;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
@ -61,6 +62,8 @@ class UserController extends Controller
|
||||||
|
|
||||||
$user->update($request->all());
|
$user->update($request->all());
|
||||||
|
|
||||||
|
event(new UserUpdateCreditsEvent($user));
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +89,7 @@ class UserController extends Controller
|
||||||
if ($user->credits + $request->credits >= 99999999) throw ValidationException::withMessages([
|
if ($user->credits + $request->credits >= 99999999) throw ValidationException::withMessages([
|
||||||
'credits' => "You can't add this amount of credits because you would exceed the credit limit"
|
'credits' => "You can't add this amount of credits because you would exceed the credit limit"
|
||||||
]);
|
]);
|
||||||
|
event(new UserUpdateCreditsEvent($user));
|
||||||
$user->increment('credits', $request->credits);
|
$user->increment('credits', $request->credits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Listeners;
|
namespace App\Listeners;
|
||||||
|
|
||||||
use App\Events\UserUpdatedEvent;
|
use App\Events\UserUpdateCreditsEvent;
|
||||||
use App\Models\Configuration;
|
use App\Models\Configuration;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
@ -14,11 +14,11 @@ class UnsuspendServers implements ShouldQueue
|
||||||
/**
|
/**
|
||||||
* Handle the event.
|
* Handle the event.
|
||||||
*
|
*
|
||||||
* @param UserUpdatedEvent $event
|
* @param UserUpdateCreditsEvent $event
|
||||||
* @return void
|
* @return void
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function handle(UserUpdatedEvent $event)
|
public function handle(UserUpdateCreditsEvent $event)
|
||||||
{
|
{
|
||||||
if ($event->user->credits > Configuration::getValueByKey('MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER' , 50)){
|
if ($event->user->credits > Configuration::getValueByKey('MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER' , 50)){
|
||||||
/** @var Server $server */
|
/** @var Server $server */
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Classes\Pterodactyl;
|
use App\Classes\Pterodactyl;
|
||||||
use App\Events\UserUpdatedEvent;
|
use App\Events\UserUpdateCreditsEvent;
|
||||||
use App\Notifications\Auth\QueuedVerifyEmail;
|
use App\Notifications\Auth\QueuedVerifyEmail;
|
||||||
use App\Notifications\WelcomeMessage;
|
use App\Notifications\WelcomeMessage;
|
||||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
|
@ -112,10 +112,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
|
|
||||||
Pterodactyl::client()->delete("/application/users/{$user->pterodactyl_id}");
|
Pterodactyl::client()->delete("/application/users/{$user->pterodactyl_id}");
|
||||||
});
|
});
|
||||||
|
|
||||||
static::updated(function (User $user){
|
|
||||||
event(new UserUpdatedEvent($user));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Events\UserUpdatedEvent;
|
use App\Events\UserUpdateCreditsEvent;
|
||||||
use App\Listeners\UnsuspendServers;
|
use App\Listeners\UnsuspendServers;
|
||||||
use App\Listeners\Verified;
|
use App\Listeners\Verified;
|
||||||
use Illuminate\Auth\Events\Registered;
|
use Illuminate\Auth\Events\Registered;
|
||||||
|
@ -22,7 +22,7 @@ class EventServiceProvider extends ServiceProvider
|
||||||
Registered::class => [
|
Registered::class => [
|
||||||
SendEmailVerificationNotification::class,
|
SendEmailVerificationNotification::class,
|
||||||
],
|
],
|
||||||
UserUpdatedEvent::class => [
|
UserUpdateCreditsEvent::class => [
|
||||||
UnsuspendServers::class
|
UnsuspendServers::class
|
||||||
],
|
],
|
||||||
SocialiteWasCalled::class => [
|
SocialiteWasCalled::class => [
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
url: form.action,
|
url: form.action,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: {
|
data: {
|
||||||
|
"_token": "{{ csrf_token() }}",
|
||||||
code: input.value
|
code: input.value
|
||||||
},
|
},
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
|
|
Loading…
Reference in a new issue