Changeset View
Changeset View
Standalone View
Standalone View
src/app/VerificationCode.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use App\Traits\BelongsToUserTrait; | |||||
use Carbon\Carbon; | use Carbon\Carbon; | ||||
use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||
/** | /** | ||||
* The eloquent definition of a VerificationCode | * The eloquent definition of a VerificationCode | ||||
* | * | ||||
* @property bool $active Active status | * @property bool $active Active status | ||||
* @property string $code The code | * @property string $code The code | ||||
* @property \Carbon\Carbon $expires_at Expiration date-time | * @property \Carbon\Carbon $expires_at Expiration date-time | ||||
* @property string $mode Mode, e.g. password-reset | * @property string $mode Mode, e.g. password-reset | ||||
* @property \App\User $user User object | |||||
* @property int $user_id User identifier | * @property int $user_id User identifier | ||||
* @property string $short_code Short code | * @property string $short_code Short code | ||||
*/ | */ | ||||
class VerificationCode extends Model | class VerificationCode extends Model | ||||
{ | { | ||||
use BelongsToUserTrait; | |||||
// Code expires after so many hours | // Code expires after so many hours | ||||
public const SHORTCODE_LENGTH = 8; | public const SHORTCODE_LENGTH = 8; | ||||
public const CODE_LENGTH = 32; | public const CODE_LENGTH = 32; | ||||
// Code expires after so many hours | // Code expires after so many hours | ||||
public const CODE_EXP_HOURS = 8; | public const CODE_EXP_HOURS = 8; | ||||
Show All 36 Lines | class VerificationCode extends Model | ||||
* | * | ||||
* @return bool True if code is expired, False otherwise | * @return bool True if code is expired, False otherwise | ||||
*/ | */ | ||||
public function isExpired() | public function isExpired() | ||||
{ | { | ||||
// @phpstan-ignore-next-line | // @phpstan-ignore-next-line | ||||
return $this->expires_at ? Carbon::now()->gte($this->expires_at) : false; | return $this->expires_at ? Carbon::now()->gte($this->expires_at) : false; | ||||
} | } | ||||
/** | |||||
* The user to which this code belongs. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |||||
*/ | |||||
public function user() | |||||
{ | |||||
return $this->belongsTo(User::class, 'user_id', 'id'); | |||||
} | |||||
} | } |