Implemented e-mail confirmations
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* E-mail confirmation
|
||||
@@ -11,15 +13,29 @@ namespace App\Models;
|
||||
* @property string $token
|
||||
* @property string $email
|
||||
* @property-read User $user
|
||||
* @method $this|Builder valid()
|
||||
*/
|
||||
class EmailConfirmation extends BaseModel
|
||||
{
|
||||
protected $guarded = [];
|
||||
const UPDATED_AT = null; // disable update timestamp
|
||||
const EXPIRATION_H = 2; // 2h
|
||||
|
||||
/** Authoring user */
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function scopeValid(Builder $query)
|
||||
{
|
||||
return $query->where('created_at', '>=',
|
||||
Carbon::now()->subHours(self::EXPIRATION_H));
|
||||
}
|
||||
|
||||
public function scopeExpired(Builder $query)
|
||||
{
|
||||
return $query->where('created_at', '<',
|
||||
Carbon::now()->subHours(self::EXPIRATION_H));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user