From ed95f02e00231b86f3e2d0a3f24c1503b4b0271a Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Sun, 28 Jun 2020 04:51:32 +0100 Subject: [PATCH] Fix error where exception appeared instead of error message This commit fixes an issue with fake MC usernames being used and resulting in a fatal exception. Displays an error msg now. --- app/Http/Middleware/UsernameUUID.php | 14 ++++++++++++-- app/UUID/UUID.php | 8 +++++++- resources/views/auth/register.blade.php | 13 +++++++++++++ resources/views/layouts/app.blade.php | 3 +++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/Http/Middleware/UsernameUUID.php b/app/Http/Middleware/UsernameUUID.php index 2463df6..29a93cf 100644 --- a/app/Http/Middleware/UsernameUUID.php +++ b/app/Http/Middleware/UsernameUUID.php @@ -20,8 +20,18 @@ class UsernameUUID $input = $request->all(); if (isset($input['uuid'])) { - $username = $input['uuid']; - $input['uuid'] = UUID::toUUID($username); + try + { + $username = $input['uuid']; + $input['uuid'] = UUID::toUUID($username); + } + catch(\InvalidArgumentException $iae) + { + report($iae); + + $request->session()->flash('error', $iae->getMessage()); + return redirect(route('register')); + } $request->replace($input); } diff --git a/app/UUID/UUID.php b/app/UUID/UUID.php index f0ca005..cee10d1 100644 --- a/app/UUID/UUID.php +++ b/app/UUID/UUID.php @@ -23,7 +23,13 @@ class UUID $username ])->body(), true); - return $response[0]['id']; + if (isset($response[0])) + { + return $response[0]['id']; + + } + + throw new \InvalidArgumentException("You must supply a valid, premium Minecraft account to sign up."); } // 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 diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index b63ddc2..6b0ed88 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -1,9 +1,22 @@ @extends('layouts.app') @section('content') + + +
+ + @if (session()->has('error')) +
+ Please verify your submission +

+ {{ session('error') }} +

+
+ @endif +
{{ __('Register') }}
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index ea847eb..197d3eb 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -12,6 +12,7 @@ + @@ -79,5 +80,7 @@ @yield('content')
+ +