From 5ff96143a7fd19e16f16f9b01441c55374b23b87 Mon Sep 17 00:00:00 2001 From: Miguel N Date: Wed, 20 Oct 2021 03:43:58 +0100 Subject: [PATCH] Fix no-license UUID bug This commit fixes a registration bug while license requirements are off. Since the app always expects a UUID, it would error out without one. --- app/Http/Controllers/Auth/RegisterController.php | 5 +---- app/Providers/AppServiceProvider.php | 2 +- app/UUID/UUID.php | 11 ++--------- .../views/dashboard/administration/players.blade.php | 6 ++---- .../dashboard/administration/staff-members.blade.php | 2 -- .../dashboard/user/profile/displayprofile.blade.php | 2 +- 6 files changed, 7 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 3140223..4139139 100755 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -120,16 +120,13 @@ class RegisterController extends Controller protected function create(array $data) { $user = User::create([ - 'uuid' => $data['uuid'], + 'uuid' => $data['uuid'] ?? "disabled", 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), 'originalIP' => config('demo.is_enabled') ? '0.0.0.0' : request()->ip(), ]); - // It's not the registration controller's concern to create a profile for the user, - // so this code has been moved to its respective observer, following the separation of concerns pattern. - $user->assignRole('user'); return $user; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 2deea95..5d9ab35 100755 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -21,6 +21,7 @@ namespace App\Providers; +use App\Facades\Options; use App\Application; use App\Observers\ApplicationObserver; use App\Observers\UserObserver; @@ -56,7 +57,6 @@ class AppServiceProvider extends ServiceProvider Schema::defaultStringLength(191); - // Keep using Bootstrap; Laravel 8 has the paginator use Tailwind. Quite opinionated tbh Paginator::useBootstrap(); User::observe(UserObserver::class); diff --git a/app/UUID/UUID.php b/app/UUID/UUID.php index 2a4de20..9a7ab32 100755 --- a/app/UUID/UUID.php +++ b/app/UUID/UUID.php @@ -28,12 +28,8 @@ use Illuminate\Support\Facades\Log; class UUID { // Caching would not be needed here since this method won't be used in pages that loop over a collection of usernames. - public function toUUID($username) + public function toUUID(string $username) { - if (is_null($username)) { - throw new \LogicException('Argument username for '.__METHOD__.' cannot be null!'); - } - $response = json_decode(Http::post(trim(config('general.urls.mojang.api')).'/profiles/minecraft', [ $username, ])->body(), true); @@ -46,11 +42,8 @@ class UUID } // Note: Caching could simply be assigning the username to it's UUID, however, to make this work, we'd need to loop over all cache items, which would be slighly ineffective - public function toUsername($uuid) + public function toUsername(string $uuid) { - if (is_null($uuid)) { - throw new \LogicException('Argument uuid for '.__METHOD__.' cannot be null!'); - } $shortUUID = substr($uuid, 0, 8); $username = Cache::remember('uuid_'.$shortUUID, now()->addDays(30), function () use ($shortUUID, $uuid) { diff --git a/resources/views/dashboard/administration/players.blade.php b/resources/views/dashboard/administration/players.blade.php index c2e3d32..d9df9d7 100755 --- a/resources/views/dashboard/administration/players.blade.php +++ b/resources/views/dashboard/administration/players.blade.php @@ -114,8 +114,7 @@ # - {{__('messages.players.ign')}} - UUID + {{__('Name')}} {{__('messages.contactlabel_email')}} {{__('messages.reusable.status')}} {{__('messages.players.reg_date')}} @@ -129,8 +128,7 @@ {{$user->id}} - {{UUID::toUsername($user->uuid)}} - {{$user->uuid}} + {{$user->name}} {{ $user->email }} @if ($user->isBanned()) diff --git a/resources/views/dashboard/administration/staff-members.blade.php b/resources/views/dashboard/administration/staff-members.blade.php index 15dc06f..332a0bf 100755 --- a/resources/views/dashboard/administration/staff-members.blade.php +++ b/resources/views/dashboard/administration/staff-members.blade.php @@ -47,7 +47,6 @@ # {{__('messages.staff.f_name')}} - UUID {{__('messages.staff.rank')}} {{__('messages.contactlabel_email')}} {{__('messages.reusable.status')}} @@ -63,7 +62,6 @@ {{ $user->id }} {{$user->name}} - {{UUID::toUsername($user->uuid)}} @foreach($user->roles as $role) {{$role->name}} diff --git a/resources/views/dashboard/user/profile/displayprofile.blade.php b/resources/views/dashboard/user/profile/displayprofile.blade.php index 71dffed..8903899 100755 --- a/resources/views/dashboard/user/profile/displayprofile.blade.php +++ b/resources/views/dashboard/user/profile/displayprofile.blade.php @@ -244,7 +244,7 @@ - +

{{__('messages.profile.edituser_consequence')}}