200 lines
5.3 KiB
PHP
200 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\UserFactory;
|
|
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;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
class User extends Authenticatable implements FilamentUser, HasAppAuthentication, HasAppAuthenticationRecovery, HasEmailAuthentication, MustVerifyEmail
|
|
{
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
|
use HasFactory, HasRoles, Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'gender',
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'agb_akzeptiert',
|
|
'app_verified_at',
|
|
'client_id',
|
|
'sport_id',
|
|
'is_multiline_direct',
|
|
'all_only_none',
|
|
'partner_show',
|
|
'partner_compare',
|
|
'bookmaker_id',
|
|
'partner_bookmaker_id',
|
|
'provider_id',
|
|
];
|
|
|
|
protected static function newFactory(): Factory
|
|
{
|
|
return UserFactory::new();
|
|
}
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
'app_authentication_secret',
|
|
'app_authentication_recovery_codes',
|
|
];
|
|
|
|
/**
|
|
* 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',
|
|
'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
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function canAccessAdminPanel(Panel $panel): bool
|
|
{
|
|
if ($panel->getId() === 'admin') {
|
|
return $this->hasVerifiedEmail();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function provider()
|
|
{
|
|
return $this->belongsTo(Provider::class);
|
|
}
|
|
|
|
public function client()
|
|
{
|
|
return $this->belongsTo(Client::class);
|
|
}
|
|
|
|
public function bookmaker()
|
|
{
|
|
return $this->belongsTo(Bookmaker::class);
|
|
}
|
|
|
|
public function partnerbookmaker()
|
|
{
|
|
return $this->belongsTo(Bookmaker::class, 'partner_bookmaker_id', 'id');
|
|
}
|
|
|
|
public function sport()
|
|
{
|
|
return $this->belongsTo(Sport::class);
|
|
}
|
|
|
|
public function bettype_user()
|
|
{
|
|
return $this->hasMany(BettypeUser::class)->where('sport_id', auth()->user()->sport_id);
|
|
}
|
|
|
|
// Accessor
|
|
public function getUserBookmakerAttribute()
|
|
{
|
|
return $this->userBookmaker()->id ?? null;
|
|
}
|
|
|
|
public function userBookmaker()
|
|
{
|
|
return Bookmaker::where('id', auth()->user()->bookmaker_id)->select('id', 'name', 'icon', 'svg')->first();
|
|
}
|
|
|
|
public static function getUser()
|
|
{
|
|
return User::with('bookmaker')->find(auth()->user()->id);
|
|
}
|
|
}
|