forked from metin2/web
Added blocking, started e-mail validation, fixed locale strings
This commit is contained in:
@ -2,13 +2,15 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\Models\Enums\AccountStatusEnum;
|
||||
use Illuminate\Auth\Notifications\VerifyEmail;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class Account extends User
|
||||
class Account extends User implements MustVerifyEmail
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
@ -26,9 +28,20 @@ class Account extends User
|
||||
*/
|
||||
protected $table = 'account';
|
||||
|
||||
const UPDATED_AT = null;
|
||||
/**
|
||||
* The name of the "created at" column.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
const CREATED_AT = 'create_time';
|
||||
|
||||
/**
|
||||
* The name of the "updated at" column.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
const UPDATED_AT = null;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
@ -59,5 +72,48 @@ class Account extends User
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'status' => AccountStatusEnum::class
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine if the user has verified their email address.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasVerifiedEmail(): bool
|
||||
{
|
||||
return $this->status != AccountStatusEnum::NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given user's email as verified.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function markEmailAsVerified(): bool
|
||||
{
|
||||
return $this->forceFill([
|
||||
'status' => AccountStatusEnum::OK,
|
||||
])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the email verification notification.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function sendEmailVerificationNotification(): void
|
||||
{
|
||||
$this->notify(new VerifyEmail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the email address that should be used for verification.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmailForVerification(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
}
|
||||
|
22
app/Models/Enums/AccountStatusEnum.php
Normal file
22
app/Models/Enums/AccountStatusEnum.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Enums;
|
||||
|
||||
enum AccountStatusEnum: string
|
||||
{
|
||||
case OK = 'OK';
|
||||
case REPAIR = 'REPAIR';
|
||||
case BLOCK = 'BLOCK';
|
||||
case NOT_AVAILABLE = 'NOTAVAIL';
|
||||
case BILLING_EXPIRED = 'NOBILL';
|
||||
case BLOCK_LOGIN = 'BLKLOGIN';
|
||||
case WEB_BLOCK = 'WEBBLK';
|
||||
|
||||
public function isBlocked(): bool
|
||||
{
|
||||
return match($this) {
|
||||
self::BLOCK, self::BILLING_EXPIRED, self::BLOCK_LOGIN, self::WEB_BLOCK => true,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user