impersonate function on customers

This commit is contained in:
Bozhidar 2024-04-26 18:22:47 +03:00
parent 10f04df2d2
commit 30e0009b94
8 changed files with 164 additions and 8 deletions

View file

@ -17,6 +17,7 @@ use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession; use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession; use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession; use Illuminate\View\Middleware\ShareErrorsFromSession;
use Modules\Customer\App\Http\Middleware\CustomerAuthenticate;
class CustomerPanelProvider extends PanelProvider class CustomerPanelProvider extends PanelProvider
{ {
@ -44,7 +45,7 @@ class CustomerPanelProvider extends PanelProvider
return $panel return $panel
->id('customer::admin') ->id('customer::admin')
->path('customer') ->path('customer')
->login()
->font('Albert Sans') ->font('Albert Sans')
->sidebarWidth('15rem') ->sidebarWidth('15rem')
// ->brandLogo(fn () => view('filament.admin.logo')) // ->brandLogo(fn () => view('filament.admin.logo'))
@ -74,6 +75,7 @@ class CustomerPanelProvider extends PanelProvider
DisableBladeIconComponents::class, DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class, DispatchServingFilamentEvent::class,
]) ])
->authGuard('web_customer')
->authMiddleware([ ->authMiddleware([
Authenticate::class, Authenticate::class,
]); ]);

View file

@ -10,6 +10,7 @@ use Filament\Forms\Form;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Table; use Filament\Tables\Table;
use STS\FilamentImpersonate\Tables\Actions\Impersonate;
class CustomerResource extends Resource class CustomerResource extends Resource
{ {
@ -113,19 +114,26 @@ class CustomerResource extends Resource
->label('Customer Name') ->label('Customer Name')
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('username') // Tables\Columns\TextColumn::make('username')
->searchable() // ->searchable()
->sortable(), // ->sortable(),
Tables\Columns\TextColumn::make('email') Tables\Columns\TextColumn::make('email')
->searchable() ->searchable()
->sortable(), ->sortable(),
]) ])
->defaultSort('id', 'desc') ->defaultSort('id', 'desc')
->filters([ ->filters([
// //
]) ])
->actions([ ->actions([
Impersonate::make('impersonate')
->guard('web_customer')
->redirectTo(route('filament.customer::admin.pages.dashboard')),
Tables\Actions\EditAction::make(), Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(), Tables\Actions\DeleteAction::make(),
]) ])

View file

@ -4,9 +4,9 @@ namespace App\Models;
use App\ApiSDK\PhyreApiSDK; use App\ApiSDK\PhyreApiSDK;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Auth\User as Authenticatable;
class Customer extends Model class Customer extends Authenticatable
{ {
use HasFactory; use HasFactory;
@ -69,4 +69,10 @@ class Customer extends Model
{ {
return $this->hasMany(HostingSubscription::class); return $this->hasMany(HostingSubscription::class);
} }
public function canBeImpersonated()
{
return true;
}
} }

View file

@ -3,12 +3,14 @@
namespace App\Models; namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail; // use Illuminate\Contracts\Auth\MustVerifyEmail;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens; use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable class User extends Authenticatable implements FilamentUser
{ {
use HasApiTokens, HasFactory, Notifiable; use HasApiTokens, HasFactory, Notifiable;
@ -42,4 +44,14 @@ class User extends Authenticatable
'email_verified_at' => 'datetime', 'email_verified_at' => 'datetime',
'password' => 'hashed', 'password' => 'hashed',
]; ];
public function canAccessPanel(Panel $panel): bool
{
return true;
}
public function canImpersonate()
{
return true;
}
} }

View file

@ -26,6 +26,7 @@
"phpseclib/phpseclib": "^3.0", "phpseclib/phpseclib": "^3.0",
"postare/blade-mdi": "^1.1", "postare/blade-mdi": "^1.1",
"spatie/ssh": "^1.10", "spatie/ssh": "^1.10",
"stechstudio/filament-impersonate": "^3.8",
"symfony/process": "^6.3", "symfony/process": "^6.3",
"symfony/yaml": "^7.0", "symfony/yaml": "^7.0",
"torann/geoip": "^3.0", "torann/geoip": "^3.0",

111
web/composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "24ce03daacd794976d8e4ad932a3acc2", "content-hash": "24c114639ffad26d47dac674a59e408e",
"packages": [ "packages": [
{ {
"name": "acmephp/core", "name": "acmephp/core",
@ -2723,6 +2723,73 @@
}, },
"time": "2024-04-09T00:35:30+00:00" "time": "2024-04-09T00:35:30+00:00"
}, },
{
"name": "lab404/laravel-impersonate",
"version": "1.7.5",
"source": {
"type": "git",
"url": "https://github.com/404labfr/laravel-impersonate.git",
"reference": "82cad73700a8699d63de169bb41abd5ae283e9a8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/404labfr/laravel-impersonate/zipball/82cad73700a8699d63de169bb41abd5ae283e9a8",
"reference": "82cad73700a8699d63de169bb41abd5ae283e9a8",
"shasum": ""
},
"require": {
"laravel/framework": "^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0 | ^11.0",
"php": "^7.2 | ^8.0"
},
"require-dev": {
"mockery/mockery": "^1.3.3",
"orchestra/testbench": "^4.0 | ^5.0 | ^6.0 | ^7.0 | ^8.0 | ^9.0",
"phpunit/phpunit": "^7.5 | ^8.0 | ^9.0 | ^10.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Lab404\\Impersonate\\ImpersonateServiceProvider"
]
}
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Lab404\\Impersonate\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marceau Casals",
"email": "marceau@casals.fr"
}
],
"description": "Laravel Impersonate is a plugin that allows to you to authenticate as your users.",
"keywords": [
"auth",
"impersonate",
"impersonation",
"laravel",
"laravel-package",
"laravel-plugin",
"package",
"plugin",
"user"
],
"support": {
"issues": "https://github.com/404labfr/laravel-impersonate/issues",
"source": "https://github.com/404labfr/laravel-impersonate/tree/1.7.5"
},
"time": "2024-03-11T14:26:14+00:00"
},
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v10.48.8", "version": "v10.48.8",
@ -6587,6 +6654,48 @@
], ],
"time": "2024-04-05T09:15:00+00:00" "time": "2024-04-05T09:15:00+00:00"
}, },
{
"name": "stechstudio/filament-impersonate",
"version": "3.8",
"source": {
"type": "git",
"url": "https://github.com/stechstudio/filament-impersonate.git",
"reference": "d24a9ffc1ef2f87940d151ca1cb2c2d2e5e524a8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/stechstudio/filament-impersonate/zipball/d24a9ffc1ef2f87940d151ca1cb2c2d2e5e524a8",
"reference": "d24a9ffc1ef2f87940d151ca1cb2c2d2e5e524a8",
"shasum": ""
},
"require": {
"filament/filament": "^3.0",
"lab404/laravel-impersonate": "^1.7"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"STS\\FilamentImpersonate\\FilamentImpersonateServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"STS\\FilamentImpersonate\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A Filament package to impersonate your users.",
"support": {
"issues": "https://github.com/stechstudio/filament-impersonate/issues",
"source": "https://github.com/stechstudio/filament-impersonate/tree/3.8"
},
"time": "2024-03-25T03:05:55+00:00"
},
{ {
"name": "swagger-api/swagger-ui", "name": "swagger-api/swagger-ui",
"version": "v5.16.0", "version": "v5.16.0",

View file

@ -40,6 +40,10 @@ return [
'driver' => 'session', 'driver' => 'session',
'provider' => 'users', 'provider' => 'users',
], ],
'web_customer' => [
'driver' => 'session',
'provider' => 'customers',
],
], ],
/* /*
@ -64,6 +68,10 @@ return [
'driver' => 'eloquent', 'driver' => 'eloquent',
'model' => App\Models\User::class, 'model' => App\Models\User::class,
], ],
'customers' => [
'driver' => 'eloquent',
'model' => App\Models\Customer::class,
],
// 'users' => [ // 'users' => [
// 'driver' => 'database', // 'driver' => 'database',
@ -97,6 +105,12 @@ return [
'expire' => 60, 'expire' => 60,
'throttle' => 60, 'throttle' => 60,
], ],
'customers' => [
'provider' => 'customers',
'table' => 'password_reset_tokens',
'expire' => 60,
'throttle' => 60,
],
], ],
/* /*

View file

@ -14,6 +14,10 @@ use phpseclib3\Net\SSH2;
| |
*/ */
Route::get('/login', function () {
return redirect(route('filament.admin.auth.login'));
})->name('login');
if (!file_exists(storage_path('installed'))) { if (!file_exists(storage_path('installed'))) {
Route::get('/', \App\Livewire\Installer::class); Route::get('/', \App\Livewire\Installer::class);