The console under console/ has its own session cookie and console guard (UseConsoleSession), so signing out or changing user there leaves the normal interface alone. Links open it in a new window through a one-time handoff key; a signed-out console asks for a PIN code or password on its own login page. Users set their 4-6 digit PIN on the profile's PIN page, and the console's change user dialog takes it on a keypad; five wrong PINs lock PIN sign-in for 15 minutes. Machine counters are cumulative: users record how much a job used and it is added to the latest reading. A maintenance record restarts the whole counter interval from the reading at the record. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
106 lines
3.1 KiB
PHP
106 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use App\Modules\Users\Domain\Enums\Locale;
|
|
use App\Modules\Users\Domain\Enums\MoneyPermission;
|
|
use App\Modules\Users\Domain\Enums\Role;
|
|
use App\Modules\Users\Infrastructure\Persistence\Eloquent\UserMoneyPermissionsModel;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Contracts\Translation\HasLocalePreference;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
/**
|
|
* Laravel's authentication model. It belongs to the Users module's
|
|
* Infrastructure layer; other modules use it only through auth() and Gate.
|
|
*
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $email
|
|
* @property Role $role
|
|
* @property bool $is_active
|
|
* @property Carbon|null $employment_ends_on
|
|
* @property int|null $supervisor_id
|
|
* @property Locale $locale
|
|
* @property-read UserMoneyPermissionsModel|null $moneyPermissions
|
|
*/
|
|
#[Fillable(['name', 'email', 'password', 'role', 'is_active', 'employment_ends_on', 'supervisor_id', 'locale'])]
|
|
#[Hidden(['password', 'remember_token', 'pin_hash'])]
|
|
class User extends Authenticatable implements HasLocalePreference
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory, Notifiable;
|
|
|
|
/**
|
|
* The column defaults, so a user made in this request has them too.
|
|
*
|
|
* @var array<string, mixed>
|
|
*/
|
|
protected $attributes = [
|
|
'locale' => 'fi',
|
|
];
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function supervisor(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'supervisor_id');
|
|
}
|
|
|
|
/**
|
|
* @return HasOne<UserMoneyPermissionsModel, $this>
|
|
*/
|
|
public function moneyPermissions(): HasOne
|
|
{
|
|
return $this->hasOne(UserMoneyPermissionsModel::class);
|
|
}
|
|
|
|
/**
|
|
* Whether the user may see the given kind of money amounts: admins and
|
|
* management always, employees and interns with a personal permission.
|
|
*/
|
|
public function canSeeMoney(MoneyPermission $permission): bool
|
|
{
|
|
if ($this->role->seesAllMoney()) {
|
|
return true;
|
|
}
|
|
|
|
return $this->role->hasPersonalMoneyPermissions()
|
|
&& ($this->moneyPermissions?->allows($permission) ?? false);
|
|
}
|
|
|
|
/**
|
|
* The language of the user's emails, such as the set-password link.
|
|
*/
|
|
public function preferredLocale(): string
|
|
{
|
|
return $this->locale->value;
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'role' => Role::class,
|
|
'is_active' => 'boolean',
|
|
'employment_ends_on' => 'date',
|
|
'locale' => Locale::class,
|
|
];
|
|
}
|
|
}
|