auth
This commit is contained in:
1 parent
b005c7677e
commit
59eea97d5a
21 files changed
+597
-779
No files matched your search
+70
-21
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Filament\Auth\MultiFactor\App\Contracts\HasAppAuthentication;
|
||||
use Filament\Auth\MultiFactor\App\Contracts\HasAppAuthenticationRecovery;
|
||||
use Filament\Auth\MultiFactor\Email\Contracts\HasEmailAuthentication;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
@@ -9,10 +12,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
class User extends Authenticatable implements FilamentUser, HasAppAuthentication, HasAppAuthenticationRecovery, HasEmailAuthentication, MustVerifyEmail
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, HasRoles, Notifiable, SoftDeletes;
|
||||
@@ -47,6 +49,8 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
'app_authentication_secret',
|
||||
'app_authentication_recovery_codes',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -60,38 +64,83 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'app_verified_at' => 'datetime',
|
||||
'app_authentication_secret' => 'encrypted',
|
||||
'app_authentication_recovery_codes' => 'encrypted:array',
|
||||
'has_email_authentication' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function getAppAuthenticationSecret(): ?string
|
||||
{
|
||||
// This method should return the user's saved app authentication secret.
|
||||
|
||||
return $this->app_authentication_secret;
|
||||
}
|
||||
|
||||
public function saveAppAuthenticationSecret(?string $secret): void
|
||||
{
|
||||
// This method should save the user's app authentication secret.
|
||||
|
||||
$this->app_authentication_secret = $secret;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getAppAuthenticationHolderName(): string
|
||||
{
|
||||
// In a user's authentication app, each account can be represented by a "holder name".
|
||||
// If the user has multiple accounts in your app, it might be a good idea to use
|
||||
// their email address as then they are still uniquely identifiable.
|
||||
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?array<string>
|
||||
*/
|
||||
public function getAppAuthenticationRecoveryCodes(): ?array
|
||||
{
|
||||
// This method should return the user's saved app authentication recovery codes.
|
||||
|
||||
return $this->app_authentication_recovery_codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> | null $codes
|
||||
*/
|
||||
public function saveAppAuthenticationRecoveryCodes(?array $codes): void
|
||||
{
|
||||
// This method should save the user's app authentication recovery codes.
|
||||
|
||||
$this->app_authentication_recovery_codes = $codes;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function hasEmailAuthentication(): bool
|
||||
{
|
||||
// This method should return true if the user has enabled email authentication.
|
||||
|
||||
return $this->has_email_authentication;
|
||||
}
|
||||
|
||||
public function toggleEmailAuthentication(bool $condition): void
|
||||
{
|
||||
// This method should save whether or not the user has enabled email authentication.
|
||||
|
||||
$this->has_email_authentication = $condition;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
Log::info('canAccessPanel');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canAccessAdminPanel(Panel $panel): bool
|
||||
{
|
||||
Log::info('canAccessAdminPanel');
|
||||
|
||||
if ($panel->getId() === 'admin') {
|
||||
return (
|
||||
str_ends_with($this->email, '@webwerkstatt.tirol') ||
|
||||
str_ends_with($this->email, '@kammerwest.at')
|
||||
)
|
||||
&& $this->hasVerifiedEmail();
|
||||
return $this->hasVerifiedEmail();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function kammer()
|
||||
{
|
||||
return $this->belongsTo(Kammer::class);
|
||||
}
|
||||
|
||||
public function bundesland()
|
||||
{
|
||||
return $this->belongsTo(Bundesland::class);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user