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