2019-05-20 07:37:41 +02:00
|
|
|
<?php
|
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
namespace App\Models;
|
2019-05-20 07:37:41 +02:00
|
|
|
|
2020-03-06 15:07:09 +01:00
|
|
|
use Illuminate\Auth\Notifications\ResetPassword;
|
2019-05-20 07:37:41 +02:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
use Laravel\Passport\HasApiTokens;
|
2021-10-15 23:46:21 +02:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2021-12-02 13:15:53 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2022-03-15 14:47:07 +01:00
|
|
|
use DarkGhostHunter\Larapass\Contracts\WebAuthnAuthenticatable;
|
|
|
|
use DarkGhostHunter\Larapass\WebAuthnAuthentication;
|
|
|
|
use DarkGhostHunter\Larapass\Notifications\AccountRecoveryNotification;
|
2019-05-20 07:37:41 +02:00
|
|
|
|
2022-03-15 14:47:07 +01:00
|
|
|
class User extends Authenticatable implements WebAuthnAuthenticatable
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
2022-03-15 14:47:07 +01:00
|
|
|
use WebAuthnAuthentication;
|
2021-12-02 13:15:53 +01:00
|
|
|
use HasApiTokens, HasFactory, Notifiable;
|
2019-05-20 07:37:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
2021-12-02 13:15:53 +01:00
|
|
|
* @var string[]
|
2019-05-20 07:37:41 +02:00
|
|
|
*/
|
|
|
|
protected $fillable = [
|
|
|
|
'name', 'email', 'password',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2021-12-02 13:15:53 +01:00
|
|
|
* The attributes that should be hidden for serialization.
|
2019-05-20 07:37:41 +02:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = [
|
|
|
|
'password', 'remember_token',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2021-12-02 13:15:53 +01:00
|
|
|
* The attributes that should be cast.
|
2019-05-20 07:37:41 +02:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
];
|
2020-01-14 23:43:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the password reset notification.
|
|
|
|
*
|
|
|
|
* @param string $token
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function sendPasswordResetNotification($token)
|
|
|
|
{
|
|
|
|
$this->notify(new ResetPassword($token));
|
2021-10-15 23:46:21 +02:00
|
|
|
|
|
|
|
Log::info('Password reset token sent');
|
2020-01-14 23:43:17 +01:00
|
|
|
}
|
2020-12-01 18:34:20 +01:00
|
|
|
|
|
|
|
/**
|
2020-12-02 23:48:16 +01:00
|
|
|
* set Email attribute
|
2020-12-01 18:34:20 +01:00
|
|
|
* @param string $value
|
|
|
|
*/
|
2022-08-26 15:57:18 +02:00
|
|
|
public function setEmailAttribute($value) : void
|
2020-12-01 18:34:20 +01:00
|
|
|
{
|
2020-12-02 23:48:16 +01:00
|
|
|
$this->attributes['email'] = strtolower($value);
|
2020-12-01 18:34:20 +01:00
|
|
|
}
|
2022-03-15 14:47:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a credential recovery email to the user.
|
|
|
|
*
|
|
|
|
* @param string $token
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function sendCredentialRecoveryNotification(string $token): void
|
|
|
|
{
|
|
|
|
$accountRecoveryNotification = new AccountRecoveryNotification($token);
|
|
|
|
$accountRecoveryNotification->toMailUsing(null);
|
|
|
|
|
2022-08-26 15:57:18 +02:00
|
|
|
$accountRecoveryNotification->createUrlUsing(function(mixed $notifiable, string $token) {
|
2022-03-15 14:47:07 +01:00
|
|
|
$url = url(
|
|
|
|
route(
|
|
|
|
'webauthn.recover',
|
|
|
|
[
|
|
|
|
'token' => $token,
|
|
|
|
'email' => $notifiable->getEmailForPasswordReset(),
|
|
|
|
],
|
|
|
|
false
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->notify($accountRecoveryNotification);
|
|
|
|
}
|
2019-05-20 07:37:41 +02:00
|
|
|
}
|