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:
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user