cleanup + auto unsuspend servers when credits update
This commit is contained in:
parent
4938384c5e
commit
b8c8cb7404
7 changed files with 79 additions and 7 deletions
32
app/Events/UserUpdatedEvent.php
Normal file
32
app/Events/UserUpdatedEvent.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UserUpdatedEvent
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public User $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ class NotificationController extends Controller
|
|||
|
||||
/**
|
||||
* Display a specific notification
|
||||
*
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $notificationId
|
||||
* @return JsonResponse
|
||||
|
@ -52,9 +52,8 @@ class NotificationController extends Controller
|
|||
|
||||
/**
|
||||
* Send a notification to an user.
|
||||
*
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $userId
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function send(Request $request)
|
||||
|
@ -88,7 +87,7 @@ class NotificationController extends Controller
|
|||
|
||||
/**
|
||||
* Delete all notifications from an user
|
||||
*
|
||||
*
|
||||
* @param int $userId
|
||||
* @return JsonResponse
|
||||
*/
|
||||
|
@ -105,7 +104,7 @@ class NotificationController extends Controller
|
|||
|
||||
/**
|
||||
* Delete a specific notification
|
||||
*
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $notificationId
|
||||
* @return JsonResponse
|
||||
|
|
30
app/Listeners/UnsuspendServers.php
Normal file
30
app/Listeners/UnsuspendServers.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\UserUpdatedEvent;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\Server;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class UnsuspendServers implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param UserUpdatedEvent $event
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function handle(UserUpdatedEvent $event)
|
||||
{
|
||||
if ($event->user->credits > Configuration::getValueByKey('MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER' , 50)){
|
||||
/** @var Server $server */
|
||||
foreach ($event->user->servers as $server){
|
||||
if ($server->isSuspended()) $server->unSuspend();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Models;
|
||||
|
||||
use App\Classes\Pterodactyl;
|
||||
use App\Events\UserUpdatedEvent;
|
||||
use App\Notifications\Auth\QueuedVerifyEmail;
|
||||
use App\Notifications\WelcomeMessage;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
|
@ -111,6 +112,10 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||
|
||||
Pterodactyl::client()->delete("/application/users/{$user->pterodactyl_id}");
|
||||
});
|
||||
|
||||
static::updated(function (User $user){
|
||||
event(new UserUpdatedEvent($user));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Events\UserUpdatedEvent;
|
||||
use App\Listeners\UnsuspendServers;
|
||||
use App\Listeners\Verified;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
|
@ -20,6 +22,9 @@ class EventServiceProvider extends ServiceProvider
|
|||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
UserUpdatedEvent::class => [
|
||||
UnsuspendServers::class
|
||||
],
|
||||
SocialiteWasCalled::class => [
|
||||
// ... other providers
|
||||
'SocialiteProviders\\Discord\\DiscordExtendSocialite@handle',
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
return [
|
||||
|
||||
'version' => '0.5',
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Name
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
{{-- select2 --}}
|
||||
<link rel="stylesheet" href="{{asset('plugins/select2/css/select2.min.css')}}">
|
||||
|
||||
|
||||
<link rel="stylesheet" href="{{asset('css/app.css')}}">
|
||||
<link rel="preload" href="{{asset('plugins/fontawesome-free/css/all.min.css')}}" as="style"
|
||||
onload="this.onload=null;this.rel='stylesheet'">
|
||||
|
@ -319,7 +319,7 @@
|
|||
<footer class="main-footer">
|
||||
<strong>Copyright © 2021-{{date('Y')}} <a href="{{url('/')}}">{{env('APP_NAME' , 'Laravel')}}</a>.</strong>
|
||||
All rights
|
||||
reserved. Powered by <a href="https://controlpanel.gg">ControlPanel</a>
|
||||
reserved. Powered by <a href="https://controlpanel.gg">ControlPanel</a>. Version <b>{{config('app')['version']}}</b>
|
||||
</footer>
|
||||
|
||||
<!-- Control Sidebar -->
|
||||
|
|
Loading…
Add table
Reference in a new issue