ldc-jeusselin/app/Models/User.php
Jérémy Munsch de4dcfb283
Closes #2 and #4
- Add status checker + admin secure packages + upgrade enum + add sentry + upgrade to sitemap generator + bump to CRMV2
- Set customer role enum and user role enum
- Update customer migration to set roles
- phpcbf
- faker local to fr
- update lang
- composer update
- bump laravel ui
- Redo all user crud
- npm bump
- Create admin command
- rearrange views
- redo all auth system
- redo customer pro bo
2023-08-21 15:43:33 +02:00

109 lines
2.8 KiB
PHP

<?php
namespace App\Models;
use App\Enums\UserRoleEnum;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Kwaadpepper\Enum\Traits\CastsEnums;
/**
* @property string $hashcode
* @property string $firstname
* @property string $lastname
* @property string $email
* @property string $password
* @property string $password_token
* @property \App\Enums\UserRoleEnum $role
* @property string $remember_token
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
*
* @package App\Models
*/
class User extends Authenticatable
{
use CanResetPassword;
use CastsEnums;
use HasFactory;
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'firstname',
'lastname',
'email',
'password',
'role'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Map attribute names to enum classes.
*
* @var array<string,string>
*/
protected $enumCasts = [
'role' => UserRoleEnum::class
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted()
{
// * EVENT CLOSURES.
static::creating(function (User $user) {
if (Hash::needsRehash($user->password)) {
$user->password = Hash::make($user->password);
}
});
static::updating(function (User $user) {
if (Hash::needsRehash($user->password)) {
$user->password = Hash::make($user->password);
}
});
}
/**
* Send a password reset notification to the user.
*
* @param string $token
* @return void
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
*/
public function sendPasswordResetNotification($token)
{
// phpcs:enable
$notification = new ResetPasswordNotification($token);
// * Changed route here only
$notification->createUrlUsing(function ($notifiable, $token) {
return url(route('bo.password.reset', [
'token' => $token,
'email' => $notifiable->getEmailForPasswordReset(),
], false));
});
$this->notify($notification);
}
}