98 lines
2.2 KiB
PHP
98 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Filament\Models\Contracts\FilamentUser;
|
|
use Filament\Panel;
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
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
|
|
{
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
|
use HasFactory, HasRoles, Notifiable, SoftDeletes;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'super_admin',
|
|
'app_verified_at',
|
|
'first_name',
|
|
'last_name',
|
|
'gender',
|
|
'company',
|
|
'uid',
|
|
'address',
|
|
'place',
|
|
'postcode',
|
|
'phone',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'app_verified_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
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 false;
|
|
}
|
|
|
|
public function kammer()
|
|
{
|
|
return $this->belongsTo(Kammer::class);
|
|
}
|
|
|
|
public function bundesland()
|
|
{
|
|
return $this->belongsTo(Bundesland::class);
|
|
}
|
|
}
|