2020-05-13 21:47:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
2020-10-21 00:01:41 +00:00
|
|
|
use Closure;
|
2020-10-21 00:29:50 +00:00
|
|
|
use App\Facades\UUID;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
2020-05-13 21:47:51 +00:00
|
|
|
|
|
|
|
class UsernameUUID
|
|
|
|
{
|
|
|
|
/**
|
2020-10-21 00:29:50 +00:00
|
|
|
* Converts a Minecraft username found in the request body to a UUID
|
2020-05-13 21:47:51 +00:00
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
|
|
|
$input = $request->all();
|
2020-10-21 00:29:50 +00:00
|
|
|
if (isset($input['uuid']))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$username = $input['uuid'];
|
|
|
|
$input['uuid'] = UUID::toUUID($username);
|
|
|
|
}
|
|
|
|
catch(\InvalidArgumentException $iae)
|
|
|
|
{
|
2020-06-28 03:51:32 +00:00
|
|
|
report($iae);
|
|
|
|
|
|
|
|
$request->session()->flash('error', $iae->getMessage());
|
|
|
|
return redirect(route('register'));
|
|
|
|
}
|
2020-05-13 21:47:51 +00:00
|
|
|
|
|
|
|
$request->replace($input);
|
|
|
|
}
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|