mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 11:04:45 +02:00
Add better profile page
This commit is contained in:
parent
b1cc4ef45c
commit
970d2b0f0f
99
app/Filament/Resources/UserResource/Pages/EditProfile.php
Normal file
99
app/Filament/Resources/UserResource/Pages/EditProfile.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Tabs;
|
||||
use Filament\Forms\Components\Tabs\Tab;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class EditProfile extends \Filament\Pages\Auth\EditProfile
|
||||
{
|
||||
protected function getForms(): array
|
||||
{
|
||||
return [
|
||||
'form' => $this->form(
|
||||
$this->makeForm()
|
||||
->schema([
|
||||
Tabs::make()->schema([
|
||||
Tab::make('Account')
|
||||
->icon('tabler-user')
|
||||
->schema([
|
||||
TextInput::make('username')
|
||||
->disabled()
|
||||
->readOnly()
|
||||
->maxLength(191)
|
||||
->unique(ignoreRecord: true)
|
||||
->autofocus(),
|
||||
|
||||
TextInput::make('email')
|
||||
->email()
|
||||
->required()
|
||||
->maxLength(191)
|
||||
->unique(ignoreRecord: true),
|
||||
|
||||
TextInput::make('password')
|
||||
->password()
|
||||
->revealable(filament()->arePasswordsRevealable())
|
||||
->rule(Password::default())
|
||||
->autocomplete('new-password')
|
||||
->dehydrated(fn ($state): bool => filled($state))
|
||||
->dehydrateStateUsing(fn ($state): string => Hash::make($state))
|
||||
->live(debounce: 500)
|
||||
->same('passwordConfirmation'),
|
||||
|
||||
TextInput::make('passwordConfirmation')
|
||||
->password()
|
||||
->revealable(filament()->arePasswordsRevealable())
|
||||
->required()
|
||||
->visible(fn (Get $get): bool => filled($get('password')))
|
||||
->dehydrated(false),
|
||||
]),
|
||||
|
||||
Tab::make('2FA')
|
||||
->icon('tabler-shield-lock')
|
||||
->schema([
|
||||
Placeholder::make('Coming soon!'),
|
||||
]),
|
||||
|
||||
Tab::make('API Keys')
|
||||
->icon('tabler-key')
|
||||
->schema([
|
||||
Placeholder::make('Coming soon!'),
|
||||
]),
|
||||
|
||||
Tab::make('SSH Keys')
|
||||
->icon('tabler-lock-code')
|
||||
->schema([
|
||||
Placeholder::make('Coming soon!'),
|
||||
]),
|
||||
|
||||
Tab::make('Activity')
|
||||
->icon('tabler-activity')
|
||||
->schema([
|
||||
Repeater::make('activity')
|
||||
->deletable(false)
|
||||
->addable(false)
|
||||
->relationship()
|
||||
|
||||
->schema([
|
||||
Placeholder::make('activity!')->label('')->content(fn (ActivityLog $log) => new HtmlString($log->htmlable())),
|
||||
])
|
||||
]),
|
||||
]),
|
||||
])
|
||||
->operation('edit')
|
||||
->model($this->getUser())
|
||||
->statePath('data')
|
||||
->inlineLabel(! static::isSimple()),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
@ -144,4 +144,29 @@ class ActivityLog extends Model
|
||||
Event::dispatch(new ActivityLogged($model));
|
||||
});
|
||||
}
|
||||
|
||||
public function htmlable()
|
||||
{
|
||||
$user = $this->actor;
|
||||
if (!$user instanceof User) {
|
||||
$user = new User([
|
||||
'email' => 'system@pelican.dev',
|
||||
'username' => 'system',
|
||||
]);
|
||||
}
|
||||
|
||||
$event = __('activity.'.str($this->event)->replace(':', '.'));
|
||||
|
||||
return "
|
||||
<div style='display: flex; align-items: center;'>
|
||||
<img width='50px' height='50px' src='{$user->getFilamentAvatarUrl()}' style='margin-right: 15px' />
|
||||
|
||||
<div>
|
||||
<p>$user->username — $this->event</p>
|
||||
<p>$event</p>
|
||||
<p>$this->ip — <span title='{$this->timestamp->format('M j, Y g:ia')}'>{$this->timestamp->diffForHumans()}</span></p>
|
||||
</div>
|
||||
</div>
|
||||
";
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers\Filament;
|
||||
|
||||
use App\Filament\Resources\UserResource\Pages\EditProfile;
|
||||
use Filament\Http\Middleware\Authenticate;
|
||||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||||
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
||||
@ -37,11 +38,7 @@ class AdminPanelProvider extends PanelProvider
|
||||
->brandName('Pelican')
|
||||
->homeUrl('/')
|
||||
->favicon('/favicon.ico')
|
||||
->userMenuItems([
|
||||
'profile' => MenuItem::make()
|
||||
->label('Edit profile')
|
||||
->url(fn (Guard $guard) => '/panel/users/' . $guard->id() . '/edit'),
|
||||
])
|
||||
->profile(EditProfile::class, false)
|
||||
->colors([
|
||||
'danger' => Color::Red,
|
||||
'gray' => Color::Zinc,
|
||||
|
Loading…
x
Reference in New Issue
Block a user