115 lines
2.4 KiB
PHP
115 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Tymon\JWTAuth\Contracts\JWTSubject;
|
|
|
|
class User extends Authenticatable implements JWTSubject
|
|
{
|
|
use Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'name', 'email', 'password', 'id', 'email_verified_at'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
];
|
|
|
|
protected $primaryKey = 'id';
|
|
|
|
protected $keyType = 'uuid';
|
|
|
|
public $incrementing = false;
|
|
|
|
public static function loginRules()
|
|
{
|
|
return [
|
|
'email' => 'required',
|
|
'password' => 'required'
|
|
];
|
|
}
|
|
|
|
public static function registerRules()
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
|
'password' => ['required', 'string', 'min:8', 'confirmed']
|
|
];
|
|
}
|
|
|
|
public static function updateRules()
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users']
|
|
];
|
|
}
|
|
|
|
public function verification()
|
|
{
|
|
return $this->hasOne('\App\Auth\EmailVerification');
|
|
}
|
|
|
|
/**
|
|
* Returns a user's login sessions
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function sessions()
|
|
{
|
|
return $this->hasMany('\App\Auth\LoginSession');
|
|
}
|
|
|
|
/**
|
|
* Get the identifier that will be stored in the subject claim of the JWT.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function getJWTIdentifier()
|
|
{
|
|
return $this->getKey();
|
|
}
|
|
|
|
/**
|
|
* Return a key value array, containing any custom claims to be added to the JWT.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getJWTCustomClaims()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function setPasswordAttribute($password)
|
|
{
|
|
if ( !empty($password) ) {
|
|
$this->attributes['password'] = Hash::make($password);
|
|
}
|
|
}
|
|
}
|