Feature/phone register (#11)
Co-authored-by: ISMAIL MASSERAN <topaz@ISMAILs-Macbook.local> Co-authored-by: ISMAIL MASSERAN <topaz@Mac.dlinkrouter.local> Reviewed-on: #11
This commit was merged in pull request #11.
This commit is contained in:
+15
-10
@@ -4,19 +4,21 @@ namespace Modules\Auth\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class EmailVerificationOtp extends Model
|
||||
class PhoneVerificationOtp extends Model
|
||||
{
|
||||
use HasUuids;
|
||||
|
||||
protected $table = 'email_verification_otps';
|
||||
protected $table = 'phone_verification_otps';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'phone_number',
|
||||
'code',
|
||||
'expires_at',
|
||||
'attempts',
|
||||
'verified_at',
|
||||
'verification_token',
|
||||
'verification_token_expires_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
@@ -24,14 +26,11 @@ class EmailVerificationOtp extends Model
|
||||
return [
|
||||
'expires_at' => 'datetime',
|
||||
'attempts' => 'integer',
|
||||
'verified_at' => 'datetime',
|
||||
'verification_token_expires_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function isExpired(): bool
|
||||
{
|
||||
return $this->expires_at->isPast();
|
||||
@@ -39,6 +38,12 @@ class EmailVerificationOtp extends Model
|
||||
|
||||
public function hasExceededMaxAttempts(): bool
|
||||
{
|
||||
return $this->attempts >= (int) config('auth.email_verification.max_attempts', 5);
|
||||
return $this->attempts >= (int) config('auth.phone_verification.max_attempts', 5);
|
||||
}
|
||||
|
||||
public function isVerificationTokenExpired(): bool
|
||||
{
|
||||
return $this->verification_token_expires_at === null
|
||||
|| $this->verification_token_expires_at->isPast();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace Modules\Auth\Entities;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Auth\MustVerifyEmail as MustVerifyEmailTrait;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
@@ -22,12 +23,13 @@ use Modules\Role\Entities\Role;
|
||||
use Modules\User\Entities\Address;
|
||||
use Modules\User\Entities\BankDetail;
|
||||
use Modules\User\Entities\Employment;
|
||||
use Modules\Auth\Notifications\VerifyEmailNotification;
|
||||
use Modules\User\Entities\Heir;
|
||||
|
||||
class User extends Authenticatable
|
||||
class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
/** @use HasFactory<\Modules\Auth\Database\Factories\UserFactory> */
|
||||
use HasApiTokens, HasFactory, HasPermissions, HasRoles, HasUuids, Impersonate, LogsActivity, Notifiable, SoftDeletes;
|
||||
use HasApiTokens, HasFactory, HasPermissions, HasRoles, HasUuids, Impersonate, LogsActivity, MustVerifyEmailTrait, Notifiable, SoftDeletes;
|
||||
|
||||
protected $table = 'users';
|
||||
|
||||
@@ -43,6 +45,7 @@ class User extends Authenticatable
|
||||
'ic_number',
|
||||
'position',
|
||||
'phone_number',
|
||||
'phone_verified_at',
|
||||
'image_url',
|
||||
'status',
|
||||
'two_factor_secret',
|
||||
@@ -129,6 +132,7 @@ class User extends Authenticatable
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'phone_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'status' => 'string',
|
||||
'gender' => 'string',
|
||||
@@ -301,9 +305,9 @@ class User extends Authenticatable
|
||||
return $currentUser->hasPermissionTo('menyamar pengguna');
|
||||
}
|
||||
|
||||
public function hasVerifiedEmail(): bool
|
||||
public function sendEmailVerificationNotification(): void
|
||||
{
|
||||
return $this->email_verified_at !== null;
|
||||
$this->notify(new VerifyEmailNotification);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,15 +319,11 @@ class User extends Authenticatable
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether credentials are valid for issuing a session (includes verified pending users).
|
||||
* Whether credentials are valid for issuing a session (includes pending users awaiting admin activation).
|
||||
*/
|
||||
public function canAuthenticate(): bool
|
||||
{
|
||||
if ($this->canLogin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasVerifiedEmail() && $this->status === 'pending';
|
||||
return in_array($this->status, ['active', 'pending'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user