From c15d0f4ef680d4fabe03a0471697e4221250d42a Mon Sep 17 00:00:00 2001 From: 1day2die Date: Tue, 29 Nov 2022 09:20:24 +0100 Subject: [PATCH 1/2] Fix Ticket System --- app/Listeners/Verified.php | 10 ++--- app/Models/User.php | 43 +++++++++++++++---- database/factories/UserFactory.php | 3 +- .../2022_11_29_075851_email_verify_d_b.php | 41 ++++++++++++++++++ resources/views/admin/users/show.blade.php | 42 ++++++++++-------- 5 files changed, 106 insertions(+), 33 deletions(-) create mode 100644 database/migrations/2022_11_29_075851_email_verify_d_b.php diff --git a/app/Listeners/Verified.php b/app/Listeners/Verified.php index 6620cad39..c4932707c 100644 --- a/app/Listeners/Verified.php +++ b/app/Listeners/Verified.php @@ -2,8 +2,6 @@ namespace App\Listeners; -use App\Models\Settings; - class Verified { /** @@ -19,12 +17,14 @@ public function __construct() /** * Handle the event. * - * @param object $event + * @param object $event * @return void */ public function handle($event) { - $event->user->increment('server_limit', config('SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_EMAIL')); - $event->user->increment('credits', config('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_EMAIL')); + if (!$event->user->email_verified_reward) { + $event->user->increment('server_limit', config('SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_EMAIL')); + $event->user->increment('credits', config('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_EMAIL')); + } } } diff --git a/app/Models/User.php b/app/Models/User.php index 450c1c440..31bb29e59 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,7 +3,6 @@ namespace App\Models; use App\Classes\Pterodactyl; -use App\Events\UserUpdateCreditsEvent; use App\Notifications\Auth\QueuedVerifyEmail; use App\Notifications\WelcomeMessage; use Illuminate\Contracts\Auth\MustVerifyEmail; @@ -110,8 +109,17 @@ public static function boot() } }); + $user->tickets()->chunk(10, function ($tickets) { + foreach ($tickets as $ticket) { + $ticket->delete(); + } + }); + + $user->ticketBlackList()->delete(); + $user->vouchers()->detach(); + $user->discordUser()->delete(); Pterodactyl::client()->delete("/application/users/{$user->pterodactyl_id}"); @@ -134,6 +142,22 @@ public function payments() return $this->hasMany(Payment::class); } + /** + * @return HasMany + */ + public function tickets() + { + return $this->hasMany(Ticket::class); + } + + /** + * @return HasMany + */ + public function ticketBlackList() + { + return $this->hasMany(TicketBlacklist::class); + } + /** * @return BelongsToMany */ @@ -209,6 +233,13 @@ public function unSuspend() return $this; } + private function getServersWithProduct() + { + return $this->servers() + ->with('product') + ->get(); + } + /** * @return string */ @@ -233,19 +264,13 @@ public function getAvatar() * @return string */ public function creditUsage() - { + { $usage = 0; foreach ($this->getServersWithProduct() as $server) { $usage += $server->product->price; } return number_format($usage, 2, '.', ''); - } - - private function getServersWithProduct() { - return $this->servers() - ->with('product') - ->get(); } /** @@ -266,7 +291,7 @@ public function verifyEmail() 'email_verified_at' => now(), ])->save(); } - + public function reVerifyEmail() { $this->forceFill([ diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 9d5704177..822e4978a 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -25,11 +25,12 @@ public function definition() return [ 'name' => $this->faker->name, 'email' => $this->faker->unique()->safeEmail, - 'credits' => $this->faker->numberBetween(0,1500), + 'credits' => $this->faker->numberBetween(0, 1500), 'last_seen' => $this->faker->dateTimeBetween(now(), '+30 days'), 'email_verified_at' => $this->faker->dateTimeBetween('-30 days', now()), 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 'remember_token' => Str::random(10), + 'email_verified' => true, ]; } } diff --git a/database/migrations/2022_11_29_075851_email_verify_d_b.php b/database/migrations/2022_11_29_075851_email_verify_d_b.php new file mode 100644 index 000000000..04e2663b0 --- /dev/null +++ b/database/migrations/2022_11_29_075851_email_verify_d_b.php @@ -0,0 +1,41 @@ +boolean('email_verified_reward')->default(false); + }); + + $existing_user = User::whereNotNull('email_verified_at')->get(); + + foreach ($existing_user as $user) { + $user->email_verified_reward = true; + $user->save(); + } + } + + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('email_verified_reward'); + }); + } +} diff --git a/resources/views/admin/users/show.blade.php b/resources/views/admin/users/show.blade.php index 4b6dd5bad..c9cf9b7cd 100644 --- a/resources/views/admin/users/show.blade.php +++ b/resources/views/admin/users/show.blade.php @@ -12,7 +12,9 @@ @@ -30,11 +32,12 @@
-

{{$user->discordUser->username}} {{$user->discordUser->locale}}

+

{{$user->discordUser->username}} {{$user->discordUser->locale}}

{{$user->discordUser->id}}

-
avatar
+
avatar
- @if($user->last_seen) {{$user->last_seen->diffForHumans()}} @else Null @endif + @if($user->last_seen) + {{$user->last_seen->diffForHumans()}} + @else + Null + @endif
- @@ -246,14 +252,15 @@ class="text-muted">Null @endif -
-
-
{{__('Referals')}} ({{__("referral-code")}}: {{$user->referral_code}})
-
-
+
+
+
{{__('Referals')}} + ({{__("referral-code")}}: {{$user->referral_code}})
+
+
- @foreach($referrals as $referral) + @foreach($referrals as $referral)
@@ -261,7 +268,8 @@ class="text-muted">Null @endif
@@ -271,17 +279,15 @@ class="text-muted">Null @endif
- @endforeach -
- + @endforeach
+
+
- - @endsection From 1c3f45d1dca14cdb9e4bf8953b3e751d9ee2ce4b Mon Sep 17 00:00:00 2001 From: 1day2die Date: Tue, 29 Nov 2022 09:32:06 +0100 Subject: [PATCH 2/2] Update app.php --- config/app.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/config/app.php b/config/app.php index b8e0c2705..19e226d86 100644 --- a/config/app.php +++ b/config/app.php @@ -1,10 +1,8 @@ '0.8.3.1', + 'version' => '0.8.3.2', /* |-------------------------------------------------------------------------- @@ -43,7 +41,7 @@ | */ - 'debug' => (bool) env('APP_DEBUG', false), + 'debug' => (bool)env('APP_DEBUG', false), /* |-------------------------------------------------------------------------- @@ -85,7 +83,7 @@ | */ - 'locale' =>"en", + 'locale' => "en", /* |-------------------------------------------------------------------------- @@ -98,7 +96,7 @@ | */ - 'available_locales' => array_map('basename', preg_replace('/\\.[^.\\s]{3,4}$/', '', glob(resource_path()."/lang/*.json", GLOB_BRACE))), + 'available_locales' => array_map('basename', preg_replace('/\\.[^.\\s]{3,4}$/', '', glob(resource_path() . "/lang/*.json", GLOB_BRACE))), /*