49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Fortify\TwoFactorAuthenticatable;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
#[Fillable(['name', 'email', 'password', 'is_admin'])]
|
|
#[Hidden(['password', 'remember_token', 'two_factor_secret', 'two_factor_recovery_codes'])]
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory, HasRoles, Notifiable, TwoFactorAuthenticatable;
|
|
|
|
/** The five operator roles that grant access to the admin console. */
|
|
public const OPERATOR_ROLES = ['Owner', 'Admin', 'Support', 'Billing', 'Read-only'];
|
|
|
|
/**
|
|
* True when this user is a CluPilot operator. Prefers RBAC roles, but keeps
|
|
* the legacy is_admin flag as a fallback so an operator can never be locked
|
|
* out of the console by a stale permission cache or a missing role.
|
|
*/
|
|
public function isOperator(): bool
|
|
{
|
|
return $this->is_admin || $this->hasAnyRole(self::OPERATOR_ROLES);
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'is_admin' => 'boolean',
|
|
];
|
|
}
|
|
}
|