kenromdavids
kenromdavids
FFilament
Created by pyr0t0n on 9/4/2023 in #❓┊help
Implement LDAP Record with Fallback
5 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
the User.php model is like this
class User extends Authenticatable implements LdapAuthenticatable
{
use HasApiTokens;
use HasFactory;
use HasProfilePhoto;
use Notifiable;
use TwoFactorAuthenticatable;
use AuthenticatesWithLdap;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'username',
'email',
'password',
];
/*more code left out because of less characters
}
class User extends Authenticatable implements LdapAuthenticatable
{
use HasApiTokens;
use HasFactory;
use HasProfilePhoto;
use Notifiable;
use TwoFactorAuthenticatable;
use AuthenticatesWithLdap;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'username',
'email',
'password',
];
/*more code left out because of less characters
}
23 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
I edited FortifyServiceProvider.php in providers like this since am using jetstream and fortify
public function boot(): void
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
/*added this*/
Fortify::authenticateUsing(function ($request) {
$validated = Auth::validate([
'samaccountname' => $request->username,
'password' => $request->password
]);

return $validated ? Auth::getLastAttempted() : null;
});
/*ends here*/
RateLimiter::for('login', function (Request $request) {
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());

return Limit::perMinute(5)->by($throttleKey);
});

RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
}
public function boot(): void
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
/*added this*/
Fortify::authenticateUsing(function ($request) {
$validated = Auth::validate([
'samaccountname' => $request->username,
'password' => $request->password
]);

return $validated ? Auth::getLastAttempted() : null;
});
/*ends here*/
RateLimiter::for('login', function (Request $request) {
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());

return Limit::perMinute(5)->by($throttleKey);
});

RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
}
23 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
in my auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'ldap',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'ldap' => [
'driver' => 'ldap',
'model' => LdapRecord\Models\ActiveDirectory\User::class,
'rules' => [],
'database' => [
'model' => App\Models\User::class,
'sync_passwords' => true,
'sync_attributes' => [
'name' => 'cn',
'email' => 'mail',
'username' => 'samaccountname',
],

'sync_existing' => [
'email' => 'mail',

],
'password_column' => 'password',
],
],

],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'ldap',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'ldap' => [
'driver' => 'ldap',
'model' => LdapRecord\Models\ActiveDirectory\User::class,
'rules' => [],
'database' => [
'model' => App\Models\User::class,
'sync_passwords' => true,
'sync_attributes' => [
'name' => 'cn',
'email' => 'mail',
'username' => 'samaccountname',
],

'sync_existing' => [
'email' => 'mail',

],
'password_column' => 'password',
],
],

],
23 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
I then added Login class in AdminPanelProvider.php
use App\Filament\Auth\Login;
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login(Login::class) //only added this
->colors([
'primary' => Color::Amber,
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
]);
}
use App\Filament\Auth\Login;
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login(Login::class) //only added this
->colors([
'primary' => Color::Amber,
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
]);
}
23 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
// this is the content
public function form(Form $form): Form
{
return $form
->schema([
//$this->getEmailFormComponent(), /*i commented out email since i wanted to use username*/
$this->getUsernameFormComponent(),
$this->getPasswordFormComponent(),
$this->getRememberFormComponent(),
])
->statePath('data');
}

protected function getUsernameFormComponent(): Component
{
return TextInput::make('username')
->label('username')
->required()
->autocomplete()
->autofocus();
}
protected function getCredentialsFromFormData(array $data): array
{
return [
'username' => $data['username'],
'password' => $data['password'],
];
}
public function authenticate(): ?LoginResponse
{
try {
$this->rateLimit(5);
} catch (TooManyRequestsException $exception) {
$this->addError('username', __('filament::login.messages.throttled', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
]));

return null;
}

$data = $this->form->getState();

if (! Filament::auth()->attempt([
'samaccountname' => $data['username'], /*changed to samaccountname */
'password' => $data['password'],
], $data['remember'])) {
$this->addError('username', __('filament::login.messages.failed'));

return null;
}

return app(LoginResponse::class);
}
// this is the content
public function form(Form $form): Form
{
return $form
->schema([
//$this->getEmailFormComponent(), /*i commented out email since i wanted to use username*/
$this->getUsernameFormComponent(),
$this->getPasswordFormComponent(),
$this->getRememberFormComponent(),
])
->statePath('data');
}

protected function getUsernameFormComponent(): Component
{
return TextInput::make('username')
->label('username')
->required()
->autocomplete()
->autofocus();
}
protected function getCredentialsFromFormData(array $data): array
{
return [
'username' => $data['username'],
'password' => $data['password'],
];
}
public function authenticate(): ?LoginResponse
{
try {
$this->rateLimit(5);
} catch (TooManyRequestsException $exception) {
$this->addError('username', __('filament::login.messages.throttled', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
]));

return null;
}

$data = $this->form->getState();

if (! Filament::auth()->attempt([
'samaccountname' => $data['username'], /*changed to samaccountname */
'password' => $data['password'],
], $data['remember'])) {
$this->addError('username', __('filament::login.messages.failed'));

return null;
}

return app(LoginResponse::class);
}
23 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
//I created a Login.php in App\Filament\Auth
<?php
namespace App\Filament\Auth;
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
use Filament\Facades\Filament;
use Filament\Forms\Form;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Component;
use Filament\Http\Responses\Auth\Contracts\LoginResponse;
use Filament\Notifications\Notification;
use Filament\Pages\Auth\Login as BaseAuth;
use Illuminate\Validation\ValidationException;

class Login extends BaseAuth
{
/*content in the next message*/
}
//I created a Login.php in App\Filament\Auth
<?php
namespace App\Filament\Auth;
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
use Filament\Facades\Filament;
use Filament\Forms\Form;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Component;
use Filament\Http\Responses\Auth\Contracts\LoginResponse;
use Filament\Notifications\Notification;
use Filament\Pages\Auth\Login as BaseAuth;
use Illuminate\Validation\ValidationException;

class Login extends BaseAuth
{
/*content in the next message*/
}
23 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
I got this working
23 replies
FFilament
Created by kenromdavids on 8/30/2023 in #❓┊help
Return value is expected to be \Filament\Tables\Table
I have tried that but it doesnt work, let me upgrade phpstorm perhaps
9 replies
FFilament
Created by kenromdavids on 8/30/2023 in #❓┊help
Return value is expected to be \Filament\Tables\Table
You mean like php artisan cache:clear? What's funny is everything is working fine in the browser but the error only shows in the editor
9 replies
FFilament
Created by kenromdavids on 8/30/2023 in #❓┊help
Return value is expected to be \Filament\Tables\Table
PHP 8.1
9 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
Basically i use username and the guard is ldap
23 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User::class, ], 'ldap' => [ 'driver' => 'ldap', 'model' => LdapRecord\Models\ActiveDirectory\User::class, 'rules' => [], 'database' => [ 'model' => App\Models\User::class, 'sync_passwords' => true, 'sync_attributes' => [ 'name' => 'cn', 'email' => 'mail', 'username' => 'samaccountname', ], 'sync_existing' => [ 'email' => 'mail', ], 'password_column' => 'password', ], ], // 'users' => [ // 'driver' => 'database', // 'table' => 'users', // ], ],
23 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
under providers
23 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
in auth.php i changed the guard to 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'ldap', ], ],
23 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Ldaprecord with filament
user model 'class User extends Authenticatable implements LdapAuthenticatable'
23 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Admin panel resources
let me look into it. thanks
12 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Admin panel resources
Thank you so much everyone .. thank you @Dan Harrin for this amazing app. lastly, let say i have superadmins, and admins, can i have myapp.test/superadmin and myapp.test/admin to have different views and tables? but all created by filament?
12 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Admin panel resources
I'm moving the whole application that has been running for years into filament, so i cant create tables and forms one by one, the generate resource functionality will help a lot and the wizard
12 replies
FFilament
Created by kenromdavids on 6/5/2023 in #❓┊help
Admin panel resources
okay, i guess i will use spartie permission to hide some tables/resources created. can i use spartie to hide the delete button only?
12 replies