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.
This commit is contained in:
2021-10-20 03:43:58 +01:00
parent 2ca891b3b0
commit 5ff96143a7
6 changed files with 7 additions and 21 deletions

View File

@@ -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) {