Archived
feat: rework logging
This commit is contained in:
1 parent
87bdbeee05
commit
2d5991988d
15 files changed
+204
-95
No files matched your search
@@ -1,9 +1,5 @@
|
||||
<x-app-layout>
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="p-6 text-nexi-black dark:text-gray-100">
|
||||
<livewire:pages.admin.logs/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
<livewire:pages.admin.logs/>
|
||||
</div>
|
||||
</x-app-layout>
|
||||
@@ -1,23 +1,23 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Log;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Volt\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
new #[Layout('layouts.app')] class extends Component
|
||||
{
|
||||
public Collection $logs;
|
||||
use WithPagination;
|
||||
|
||||
public function mount(): void
|
||||
public function with(): array
|
||||
{
|
||||
$this->getLogs();
|
||||
}
|
||||
$logs = Log::with(['user', 'loggable'])
|
||||
->orderByDesc('created_at')
|
||||
->paginate(15);
|
||||
|
||||
public function getLogs(): void
|
||||
{
|
||||
// TODO: look into pagination for this.
|
||||
$this->logs = Log::with(['user', 'quote', 'requestedQuote'])->get()->sortByDesc('created_at');
|
||||
return [
|
||||
'logs' => $logs,
|
||||
];
|
||||
}
|
||||
}; ?>
|
||||
|
||||
@@ -30,38 +30,56 @@ new #[Layout('layouts.app')] class extends Component
|
||||
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-nexi-black dark:text-gray-200 sm:pl-6">
|
||||
User
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="px-3 py-3.5 text-left text-sm font-semibold text-nexi-black dark:text-gray-200">
|
||||
Type
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="px-3 py-3.5 text-left text-sm font-semibold text-nexi-black dark:text-gray-200">
|
||||
Entity ID
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="px-3 py-3.5 text-left text-sm font-semibold text-nexi-black dark:text-gray-200">
|
||||
Action
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="px-3 py-3.5 text-left text-sm font-semibold text-nexi-black dark:text-gray-200">
|
||||
Logs
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="px-3 py-3.5 text-left text-sm font-semibold text-nexi-black dark:text-gray-200">
|
||||
Type
|
||||
IP
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($logs as $log)
|
||||
<tr>
|
||||
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm text-nexi-black dark:text-gray-200 sm:pl-0">
|
||||
{{ $log?->user->fullName() ?? 'N/A' }}
|
||||
<td class="relative py-4 px-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ $log?->user?->full_name ?? 'Anonymous' }}
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-nexi-black dark:text-gray-200">
|
||||
<td class="relative py-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ str_replace('App\Models\\', '', $log->loggable_type) }}
|
||||
</td>
|
||||
<td class="relative py-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ $log->loggable_id }}
|
||||
</td>
|
||||
<td class="relative py-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ $log->action }}
|
||||
</td>
|
||||
<td class="relative py-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ $log->content }}
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-nexi-black dark:text-gray-200">
|
||||
@if (!empty($log->quote_id))
|
||||
Quote - {{ $log->quote_id }}
|
||||
@elseif (!empty($log->requested_quote_id))
|
||||
Requsted Quote - ID: {{ $log->requested_quote_id }}
|
||||
@else
|
||||
N/A
|
||||
@endif
|
||||
<td class="relative py-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ $log->ip }}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
{{ $logs->links() }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\LogAction;
|
||||
use App\Models\Log;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Attributes\Layout;
|
||||
@@ -19,8 +20,12 @@ new #[Layout('layouts.app')] class extends Component
|
||||
$response = Http::post(config('bot.webhook'), ['text' => $validated['quote']]);
|
||||
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'content' => "Quote sent. {$validated['quote']}",
|
||||
'user_id' => auth()->user()->id,
|
||||
'loggable_type' => Log::class,
|
||||
'loggable_id' => null,
|
||||
'action' => LogAction::SEND,
|
||||
'content' => $validated['quote'],
|
||||
'ip' => request()->ip(),
|
||||
]);
|
||||
|
||||
$this->quote = '';
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\LogAction;
|
||||
use App\Models\Log;
|
||||
use App\Models\User;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
@@ -41,8 +43,12 @@ new #[Layout('layouts.guest')] class extends Component
|
||||
session()->regenerate();
|
||||
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'content' => "Quote sent. {$quote}",
|
||||
'user_id' => auth()->user()->id,
|
||||
'loggable_type' => User::class,
|
||||
'loggable_id' => auth()->user()->id,
|
||||
'action' => LogAction::ACCESS,
|
||||
'content' => 'User logged in',
|
||||
'ip' => request()->ip(),
|
||||
]);
|
||||
|
||||
$this->redirect(
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\LogAction;
|
||||
use App\Models\User;
|
||||
use App\Models\Log;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
@@ -60,8 +62,12 @@ new #[Layout('layouts.guest')] class extends Component
|
||||
session()->flash('status', __($status));
|
||||
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'content' => "Quote sent. {$quote}",
|
||||
'user_id' => auth()->user()->id,
|
||||
'loggable_type' => User::class,
|
||||
'loggable_id' => auth()?->user()?->id,
|
||||
'action' => LogAction::UPDATE,
|
||||
'content' => 'User reset password via reset',
|
||||
'ip' => request()->ip(),
|
||||
]);
|
||||
|
||||
$this->redirectRoute('login', navigate: true);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\LogAction;
|
||||
use App\Models\Log;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
@@ -30,8 +32,12 @@ new class extends Component
|
||||
]);
|
||||
|
||||
Log::create([
|
||||
'user_id' => auth()?->user()?->id,
|
||||
'content' => "Quote sent. {$quote}",
|
||||
'user_id' => auth()->user()->id,
|
||||
'loggable_type' => User::class,
|
||||
'loggable_id' => auth()?->user()?->id,
|
||||
'action' => LogAction::UPDATE,
|
||||
'content' => 'User updated password',
|
||||
'ip' => request()->ip(),
|
||||
]);
|
||||
|
||||
$this->reset('current_password', 'password', 'password_confirmation');
|
||||
@@ -53,25 +59,41 @@ new class extends Component
|
||||
|
||||
<form wire:submit="updatePassword" class="mt-6 space-y-6">
|
||||
<div>
|
||||
<x-input-label for="current_password" :value="__('Current Password')" />
|
||||
<x-text-input wire:model="current_password" id="current_password" name="current_password" type="password" class="mt-1 block w-full" autocomplete="current-password" />
|
||||
<x-input-error :messages="$errors->get('current_password')" class="mt-2" />
|
||||
<x-input-label for="current_password" :value="__('Current Password')"/>
|
||||
<x-text-input wire:model="current_password"
|
||||
id="current_password"
|
||||
name="current_password"
|
||||
type="password"
|
||||
class="mt-1 block w-full"
|
||||
autocomplete="current-password"/>
|
||||
<x-input-error :messages="$errors->get('current_password')" class="mt-2"/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<x-input-label for="password" :value="__('New Password')" />
|
||||
<x-text-input wire:model="password" id="password" name="password" type="password" class="mt-1 block w-full" autocomplete="new-password" />
|
||||
<x-input-error :messages="$errors->get('password')" class="mt-2" />
|
||||
<x-input-label for="password" :value="__('New Password')"/>
|
||||
<x-text-input wire:model="password"
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
class="mt-1 block w-full"
|
||||
autocomplete="new-password"/>
|
||||
<x-input-error :messages="$errors->get('password')" class="mt-2"/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<x-input-label for="password_confirmation" :value="__('Confirm Password')" />
|
||||
<x-text-input wire:model="password_confirmation" id="password_confirmation" name="password_confirmation" type="password" class="mt-1 block w-full" autocomplete="new-password" />
|
||||
<x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" />
|
||||
<x-input-label for="password_confirmation" :value="__('Confirm Password')"/>
|
||||
<x-text-input wire:model="password_confirmation"
|
||||
id="password_confirmation"
|
||||
name="password_confirmation"
|
||||
type="password"
|
||||
class="mt-1 block w-full"
|
||||
autocomplete="new-password"/>
|
||||
<x-input-error :messages="$errors->get('password_confirmation')" class="mt-2"/>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<x-primary-button wire:loading.attr="disabled" wire:loading.class="opacity-50">{{ __('Save') }}</x-primary-button>
|
||||
<x-primary-button wire:loading.attr="disabled"
|
||||
wire:loading.class="opacity-50">{{ __('Save') }}</x-primary-button>
|
||||
|
||||
<x-action-message class="mr-3" on="password-updated">
|
||||
{{ __('Saved.') }}
|
||||
|
||||
Reference in new issue
Block a user