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:
parent
2ca891b3b0
commit
5ff96143a7
@ -120,16 +120,13 @@ class RegisterController extends Controller
|
|||||||
protected function create(array $data)
|
protected function create(array $data)
|
||||||
{
|
{
|
||||||
$user = User::create([
|
$user = User::create([
|
||||||
'uuid' => $data['uuid'],
|
'uuid' => $data['uuid'] ?? "disabled",
|
||||||
'name' => $data['name'],
|
'name' => $data['name'],
|
||||||
'email' => $data['email'],
|
'email' => $data['email'],
|
||||||
'password' => Hash::make($data['password']),
|
'password' => Hash::make($data['password']),
|
||||||
'originalIP' => config('demo.is_enabled') ? '0.0.0.0' : request()->ip(),
|
'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');
|
$user->assignRole('user');
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Facades\Options;
|
||||||
use App\Application;
|
use App\Application;
|
||||||
use App\Observers\ApplicationObserver;
|
use App\Observers\ApplicationObserver;
|
||||||
use App\Observers\UserObserver;
|
use App\Observers\UserObserver;
|
||||||
@ -56,7 +57,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
Schema::defaultStringLength(191);
|
Schema::defaultStringLength(191);
|
||||||
|
|
||||||
// Keep using Bootstrap; Laravel 8 has the paginator use Tailwind. Quite opinionated tbh
|
|
||||||
Paginator::useBootstrap();
|
Paginator::useBootstrap();
|
||||||
|
|
||||||
User::observe(UserObserver::class);
|
User::observe(UserObserver::class);
|
||||||
|
@ -28,12 +28,8 @@ use Illuminate\Support\Facades\Log;
|
|||||||
class UUID
|
class UUID
|
||||||
{
|
{
|
||||||
// Caching would not be needed here since this method won't be used in pages that loop over a collection of usernames.
|
// 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', [
|
$response = json_decode(Http::post(trim(config('general.urls.mojang.api')).'/profiles/minecraft', [
|
||||||
$username,
|
$username,
|
||||||
])->body(), true);
|
])->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
|
// 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);
|
$shortUUID = substr($uuid, 0, 8);
|
||||||
$username = Cache::remember('uuid_'.$shortUUID, now()->addDays(30), function () use ($shortUUID, $uuid) {
|
$username = Cache::remember('uuid_'.$shortUUID, now()->addDays(30), function () use ($shortUUID, $uuid) {
|
||||||
|
@ -114,8 +114,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>{{__('messages.players.ign')}}</th>
|
<th>{{__('Name')}}</th>
|
||||||
<th>UUID</th>
|
|
||||||
<th>{{__('messages.contactlabel_email')}}</th>
|
<th>{{__('messages.contactlabel_email')}}</th>
|
||||||
<th>{{__('messages.reusable.status')}}</th>
|
<th>{{__('messages.reusable.status')}}</th>
|
||||||
<th>{{__('messages.players.reg_date')}}</th>
|
<th>{{__('messages.players.reg_date')}}</th>
|
||||||
@ -129,8 +128,7 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{$user->id}}</td>
|
<td>{{$user->id}}</td>
|
||||||
<td>{{UUID::toUsername($user->uuid)}}</td>
|
<td>{{$user->name}}</td>
|
||||||
<td>{{$user->uuid}}</td>
|
|
||||||
<td>{{ $user->email }}</td>
|
<td>{{ $user->email }}</td>
|
||||||
<td>
|
<td>
|
||||||
@if ($user->isBanned())
|
@if ($user->isBanned())
|
||||||
|
@ -47,7 +47,6 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>{{__('messages.staff.f_name')}}</th>
|
<th>{{__('messages.staff.f_name')}}</th>
|
||||||
<th>UUID</th>
|
|
||||||
<th>{{__('messages.staff.rank')}}</th>
|
<th>{{__('messages.staff.rank')}}</th>
|
||||||
<th>{{__('messages.contactlabel_email')}}</th>
|
<th>{{__('messages.contactlabel_email')}}</th>
|
||||||
<th>{{__('messages.reusable.status')}}</th>
|
<th>{{__('messages.reusable.status')}}</th>
|
||||||
@ -63,7 +62,6 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{ $user->id }}</td>
|
<td>{{ $user->id }}</td>
|
||||||
<td>{{$user->name}}</td>
|
<td>{{$user->name}}</td>
|
||||||
<td>{{UUID::toUsername($user->uuid)}}</td>
|
|
||||||
<td>
|
<td>
|
||||||
@foreach($user->roles as $role)
|
@foreach($user->roles as $role)
|
||||||
<span class="badge badge-info badge-sm">{{$role->name}}</span>
|
<span class="badge badge-info badge-sm">{{$role->name}}</span>
|
||||||
|
@ -244,7 +244,7 @@
|
|||||||
<input {{ ($demoActive) ? 'disabled' : '' }} id="name" type="text" name="name" class="form-control" required value="{{ $profile->user->name }}" />
|
<input {{ ($demoActive) ? 'disabled' : '' }} id="name" type="text" name="name" class="form-control" required value="{{ $profile->user->name }}" />
|
||||||
|
|
||||||
<label for="uuid">Mojang UUID</label>
|
<label for="uuid">Mojang UUID</label>
|
||||||
<input {{ ($demoActive) ? 'disabled' : '' }} id="uuid" type="text" name="uuid" class="form-control" required value="{{ $profile->user->uuid }}" />
|
<input {{ ($demoActive) ? 'disabled' : '' }} id="uuid" type="text" name="uuid" class="form-control" required value="{{ $profile->user->uuid ?? "disabled" }}" />
|
||||||
<p class="text-muted text-sm">
|
<p class="text-muted text-sm">
|
||||||
<i class="fas fa-exclamation-triangle"></i> {{__('messages.profile.edituser_consequence')}}
|
<i class="fas fa-exclamation-triangle"></i> {{__('messages.profile.edituser_consequence')}}
|
||||||
</p>
|
</p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user