All checks were successful
linter / quality (pull_request) Successful in 1m35s
security / Dependency Audit (pull_request) Successful in 1m19s
security / Static Analysis (pull_request) Successful in 1m32s
tests / ci (8.4) (pull_request) Successful in 2m36s
tests / ci (8.5) (pull_request) Successful in 1m37s
- Add missing LDAP env vars to .env.example (host, base DN, bind credentials) - Use 'uid' instead of 'username' as the LDAP lookup attribute in Auth::attempt - Override getLdapGuidColumn/getLdapDomainColumn in User model to match migration column names (ldap_guid/ldap_domain vs default guid/domain)
87 lines
2.0 KiB
PHP
87 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Filament\Models\Contracts\FilamentUser;
|
|
use Filament\Panel;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Str;
|
|
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;
|
|
use LdapRecord\Laravel\Auth\HasLdapUser;
|
|
use LdapRecord\Laravel\Auth\LdapAuthenticatable;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
class User extends Authenticatable implements FilamentUser, LdapAuthenticatable
|
|
{
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
|
use HasFactory, Notifiable, HasRoles, AuthenticatesWithLdap, HasLdapUser;
|
|
|
|
/**
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'username',
|
|
'phone',
|
|
'department',
|
|
'title',
|
|
'ldap_guid',
|
|
'ldap_domain',
|
|
];
|
|
|
|
/**
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
];
|
|
}
|
|
|
|
public function initials(): string
|
|
{
|
|
return Str::of($this->name)
|
|
->explode(' ')
|
|
->take(2)
|
|
->map(fn ($word) => Str::substr($word, 0, 1))
|
|
->implode('');
|
|
}
|
|
|
|
public function canAccessPanel(Panel $panel): bool
|
|
{
|
|
return $this->hasRole('administrator');
|
|
}
|
|
|
|
public function getLdapGuidColumn(): string
|
|
{
|
|
return 'ldap_guid';
|
|
}
|
|
|
|
public function getLdapDomainColumn(): string
|
|
{
|
|
return 'ldap_domain';
|
|
}
|
|
|
|
public function emergencyContacts(): HasMany
|
|
{
|
|
return $this->hasMany(EmergencyContact::class);
|
|
}
|
|
|
|
public function travelRequests(): HasMany
|
|
{
|
|
return $this->hasMany(TravelRequest::class);
|
|
}
|
|
}
|