Changeset View
Changeset View
Standalone View
Standalone View
src/app/VerificationCode.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
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 string $code | * @property bool $active Active status | ||||
* @property string $mode | * @property string $code The code | ||||
* @property \App\User $user | * @property \Carbon\Carbon $expires_at Expiration date-time | ||||
* @property int $user_id | * @property string $mode Mode, e.g. password-reset | ||||
* @property string $short_code | * @property \App\User $user User object | ||||
* @property int $user_id User identifier | |||||
* @property string $short_code Short code | |||||
*/ | */ | ||||
class VerificationCode extends Model | class VerificationCode extends Model | ||||
{ | { | ||||
// 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; | ||||
vanmeeuwen: Here's it 8 hours, elsewhere I see 7 days. | |||||
/** | /** | ||||
* The primary key associated with the table. | * The primary key associated with the table. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $primaryKey = 'code'; | protected $primaryKey = 'code'; | ||||
Show All 14 Lines | class VerificationCode extends Model | ||||
/** | /** | ||||
* Indicates if the model should be timestamped. | * Indicates if the model should be timestamped. | ||||
* | * | ||||
* @var bool | * @var bool | ||||
*/ | */ | ||||
public $timestamps = false; | public $timestamps = false; | ||||
/** | /** | ||||
* The attributes that are mass assignable. | * Casts properties as type | ||||
* | * | ||||
* @var array | * @var array | ||||
*/ | */ | ||||
protected $fillable = ['user_id', 'code', 'short_code', 'mode', 'expires_at']; | protected $casts = [ | ||||
'active' => 'boolean', | |||||
'expires_at' => 'datetime', | |||||
]; | |||||
/** | /** | ||||
* The attributes that should be mutated to dates. | * The attributes that are mass assignable. | ||||
* | * | ||||
* @var array | * @var array | ||||
*/ | */ | ||||
protected $dates = ['expires_at']; | protected $fillable = ['user_id', 'code', 'short_code', 'mode', 'expires_at', 'active']; | ||||
/** | /** | ||||
* Generate a short code (for human). | * Generate a short code (for human). | ||||
* | * | ||||
* @return string | * @return string | ||||
*/ | */ | ||||
public static function generateShortCode(): string | public static function generateShortCode(): string | ||||
Show All 10 Lines | class VerificationCode extends Model | ||||
*/ | */ | ||||
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 setting belongs. | * The user to which this code belongs. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
*/ | */ | ||||
public function user() | public function user() | ||||
{ | { | ||||
return $this->belongsTo('\App\User', 'user_id', 'id'); | return $this->belongsTo('\App\User', 'user_id', 'id'); | ||||
} | } | ||||
} | } |
Here's it 8 hours, elsewhere I see 7 days.