feat(Password process for new admin, cleaning translations)
All checks were successful
Deploy Roxane to Preprod / deploy (push) Successful in 1m21s
All checks were successful
Deploy Roxane to Preprod / deploy (push) Successful in 1m21s
This commit is contained in:
@@ -3,9 +3,44 @@
|
||||
namespace App\Filament\Resources\Users\Pages;
|
||||
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use App\Models\User;
|
||||
use App\Notifications\AdminInvitationNotification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateUser extends CreateRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
/**
|
||||
* Generate a random password if none was provided, so the invitation
|
||||
* flow can proceed without requiring the admin to set one manually.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
if (empty($data['password'])) {
|
||||
$data['password'] = Str::random(32);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an invitation email after the user is created so they can
|
||||
* set their own password via the admin panel reset flow.
|
||||
*/
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->record;
|
||||
$token = Password::broker()->createToken($user);
|
||||
|
||||
$user->notify(new AdminInvitationNotification($token));
|
||||
Log::info('User invited: '.$user->email);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ class UserForm
|
||||
->required(),
|
||||
TextInput::make('email')
|
||||
->label(User::getAttributeLabel('email'))
|
||||
->label('Email address')
|
||||
->email()
|
||||
->required(),
|
||||
DateTimePicker::make('email_verified_at')
|
||||
@@ -28,14 +27,19 @@ class UserForm
|
||||
TextInput::make('password')
|
||||
->label(User::getAttributeLabel('password'))
|
||||
->password()
|
||||
->revealable()
|
||||
->dehydrated(fn ($state) => filled($state))
|
||||
->dehydrateStateUsing(fn ($state) => Hash::make($state)),
|
||||
->dehydrateStateUsing(fn ($state) => Hash::make($state))
|
||||
->hint(fn (string $operation) => $operation === 'create'
|
||||
? __('users.hints.password_create')
|
||||
: __('users.hints.password_edit'))
|
||||
->hintIcon('heroicon-m-information-circle'),
|
||||
Select::make('role')
|
||||
->label(User::getAttributeLabel('role'))
|
||||
->relationship('roles', 'name')
|
||||
->multiple()
|
||||
->preload()
|
||||
->searchable()
|
||||
->searchable(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\Users\Tables;
|
||||
|
||||
use App\Models\User;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
@@ -15,11 +16,13 @@ class UsersTable
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label(User::getAttributeLabel('name'))
|
||||
->searchable(),
|
||||
TextColumn::make('email')
|
||||
->label('Email address')
|
||||
->label(User::getAttributeLabel('email'))
|
||||
->searchable(),
|
||||
TextColumn::make('email_verified_at')
|
||||
->label(User::getAttributeLabel('email_verified_at'))
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
TextColumn::make('created_at')
|
||||
|
||||
Reference in New Issue
Block a user