Skip to content

Commit

Permalink
Login links used-at w-i-p
Browse files Browse the repository at this point in the history
  • Loading branch information
mooxbot committed Apr 27, 2024
1 parent 5cb06ad commit a8acdfd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions database/migrations/create_login_links_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ return new class extends Migration
$table->string('email')->index();
$table->string('token')->index()->nullable;
$table->dateTime('expires_at');
$table->dateTime('used_at');
$table->string('user_agent')->nullable();
$table->ipAddress('ip_address')->nullable();
$table->timestamps();
Expand Down
3 changes: 3 additions & 0 deletions resources/lang/en/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
'totalthree' => 'Login Links Invalid',
'token' => 'Token',
'expires_at' => 'Expires at',
'used_at' => 'Used at',
'used' => 'Used',
'created_at' => 'Created at',
'email' => 'E-Mail',
'user_agent' => 'User Agent',
'ip_address' => 'IP-Adresse',
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/LoginLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function authenticate($userId, $token)
$userType = 'App\Models\User';
}

$loginLink->update(['token' => 'used']);
$loginLink->update(['used_at' => now()]);

$userModel = Config::get('login-link.user_models.'.$userType, User::class);
$user = $userModel::findOrFail($userId);
Expand Down
2 changes: 2 additions & 0 deletions src/Models/LoginLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class LoginLink extends Model
'email',
'token',
'expires_at',
'used_at',
'user_agent',
'ip_address',
];

protected $casts = [
'expires_at' => 'datetime',
'used_at' => 'datetime',
];

/**
Expand Down
27 changes: 17 additions & 10 deletions src/Resources/LoginLinkResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Filament\Resources\Resource;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Config;
Expand Down Expand Up @@ -39,8 +40,10 @@ public static function form(Form $form): Form
->columnSpan(2),
TextInput::make('token')
->label(__('login-link::translations.token'))
->maxLength(255),
->maxLength(255)
->columnSpan(2),
DateTimePicker::make('expires_at'),
DateTimePicker::make('used_at'),
Select::make('user_type')
->options(function () {
$models = Config::get('login-link.user_models', []);
Expand Down Expand Up @@ -70,24 +73,28 @@ public static function table(Table $table): Table
{
return $table
->columns([
IconColumn::make('used')
->label('Valid')
->icons([
'heroicon-o-x-circle' => fn ($record) => empty($record->used_at),
'heroicon-o-check-circle' => fn ($record) => ! empty($record->used_at),
])
->tooltip(fn ($record) => empty($record->used_at) ? 'Not Used' : 'Used')
->sortable(),
TextColumn::make('email')
->label(__('login-link::translations.email'))
->sortable(),
TextColumn::make('token')
->label(__('login-link::translations.token'))
->sortable(),
TextColumn::make('expires_at')
TextColumn::make('created_at')
->label(__('login-link::translations.expires_at'))
->sortable(),
TextColumn::make('user_agent')
->label(__('login-link::translations.user_agent'))
->since()
->sortable(),
TextColumn::make('expires_at')
->label(__('login-link::translations.expires_at'))
->since()
->sortable(),
TextColumn::make('ip_address')
->label(__('login-link::translations.ip_address'))
TextColumn::make('used_at')
->label(__('login-link::translations.used_at'))
->since()
->sortable(),
TextColumn::make('user_type')
->label(__('login-link::translations.user_type'))
Expand Down

0 comments on commit a8acdfd

Please sign in to comment.