staffmanager/app/Http/Middleware/UsernameUUID.php
Miguel Nogueira 4eb115d165 Revert "Apply fixes from StyleCI (pull request #6)"
This reverts pull request #6.

> This pull request applies code style fixes from an analysis carried out by [StyleCI](https://bitbucket.styleci.io).
> 
> For more information, click [here](https://bitbucket.styleci.io/analyses/a2Jl7D).
2020-10-21 00:29:50 +00:00

41 lines
934 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use App\Facades\UUID;
use Illuminate\Support\Facades\Http;
class UsernameUUID
{
/**
* Converts a Minecraft username found in the request body to a UUID
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$input = $request->all();
if (isset($input['uuid']))
{
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);
}
return $next($request);
}
}