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

View file

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

View file

@ -4,9 +4,9 @@ namespace App\Models;
use App\ApiSDK\PhyreApiSDK;
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;
@ -69,4 +69,10 @@ class Customer extends Model
{
return $this->hasMany(HostingSubscription::class);
}
public function canBeImpersonated()
{
return true;
}
}

View file

@ -3,12 +3,14 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
class User extends Authenticatable implements FilamentUser
{
use HasApiTokens, HasFactory, Notifiable;
@ -42,4 +44,14 @@ class User extends Authenticatable
'email_verified_at' => 'datetime',
'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",
"postare/blade-mdi": "^1.1",
"spatie/ssh": "^1.10",
"stechstudio/filament-impersonate": "^3.8",
"symfony/process": "^6.3",
"symfony/yaml": "^7.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",
"This file is @generated automatically"
],
"content-hash": "24ce03daacd794976d8e4ad932a3acc2",
"content-hash": "24c114639ffad26d47dac674a59e408e",
"packages": [
{
"name": "acmephp/core",
@ -2723,6 +2723,73 @@
},
"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",
"version": "v10.48.8",
@ -6587,6 +6654,48 @@
],
"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",
"version": "v5.16.0",

View file

@ -40,6 +40,10 @@ return [
'driver' => 'session',
'provider' => 'users',
],
'web_customer' => [
'driver' => 'session',
'provider' => 'customers',
],
],
/*
@ -64,6 +68,10 @@ return [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'customers' => [
'driver' => 'eloquent',
'model' => App\Models\Customer::class,
],
// 'users' => [
// 'driver' => 'database',
@ -97,6 +105,12 @@ return [
'expire' => 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'))) {
Route::get('/', \App\Livewire\Installer::class);