2026-04-28 16:38:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Mails\Auth\LinkResetPasswordMail;
|
|
|
|
|
use App\Models\UserPassword;
|
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
use Uwil\LaravelBackend\Models\User as BackendUser;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extends the package User model with password-based authentication support.
|
|
|
|
|
*
|
|
|
|
|
* @property-read \App\Models\UserPassword|null $userPassword Associated password.
|
|
|
|
|
* @see \Uwil\LaravelBackend\Models\User For all other properties and methods.
|
|
|
|
|
*/
|
|
|
|
|
class User extends BackendUser
|
|
|
|
|
{
|
2026-05-20 15:02:43 +02:00
|
|
|
/**
|
|
|
|
|
* Relations should be included in the cache.
|
|
|
|
|
*
|
|
|
|
|
* @var list<string>
|
|
|
|
|
*/
|
|
|
|
|
public static $cacheRelations = [
|
|
|
|
|
'userPassword',
|
|
|
|
|
'sites',
|
|
|
|
|
];
|
|
|
|
|
|
2026-04-28 16:38:04 +02:00
|
|
|
/**
|
|
|
|
|
* Get the password for authentication.
|
|
|
|
|
* Retrieves the hashed password from the related user_passwords table.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function getAuthPassword(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->userPassword()->value('password') ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send the password reset notification to the user.
|
|
|
|
|
*
|
|
|
|
|
* @param string $token
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
// phpstan-ignore-next-line
|
|
|
|
|
// phpcs:ignore
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function sendPasswordResetNotification($token): void
|
|
|
|
|
{
|
|
|
|
|
$url = sprintf(
|
|
|
|
|
"%s?email=%s",
|
|
|
|
|
url(route('back.reset-password', ['token' => $token], false)),
|
|
|
|
|
urlencode($this->getEmailForPasswordReset())
|
|
|
|
|
);
|
2026-05-19 12:25:21 +02:00
|
|
|
|
2026-04-28 16:38:04 +02:00
|
|
|
Mail::send(new LinkResetPasswordMail($url, $this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// * RELATIONSHIPS.
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the user's associated password.
|
|
|
|
|
*
|
2026-05-19 12:25:21 +02:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne<\App\Models\UserPassword,\App\Models\User>
|
2026-04-28 16:38:04 +02:00
|
|
|
*/
|
|
|
|
|
public function userPassword(): \Illuminate\Database\Eloquent\Relations\HasOne
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(UserPassword::class);
|
|
|
|
|
}
|
2026-05-20 15:02:43 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get sites associated to the brand.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany<\App\Models\Site>
|
|
|
|
|
*/
|
|
|
|
|
public function sites(): \Illuminate\Database\Eloquent\Relations\MorphToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->morphToMany(
|
|
|
|
|
Site::class,
|
|
|
|
|
'sitable',
|
|
|
|
|
'sitables',
|
|
|
|
|
'sitable_id',
|
|
|
|
|
'site_id',
|
|
|
|
|
)->withPivot('created_at');
|
|
|
|
|
}
|
2026-05-19 12:25:21 +02:00
|
|
|
}
|