1
|
|
|
<?php namespace Arcanedev\LaravelAuth\Models; |
2
|
|
|
|
3
|
|
|
use Carbon\Carbon; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class PasswordReset |
7
|
|
|
* |
8
|
|
|
* @package Arcanedev\LaravelAuth\Models |
9
|
|
|
* @author ARCANEDEV <[email protected]> |
10
|
|
|
* |
11
|
|
|
* @property string email |
12
|
|
|
* @property string token |
13
|
|
|
* @property \Carbon\Carbon created_at |
14
|
|
|
*/ |
15
|
|
|
class PasswordReset extends AbstractModel |
16
|
|
|
{ |
17
|
|
|
/* ----------------------------------------------------------------- |
18
|
|
|
| Properties |
19
|
|
|
| ----------------------------------------------------------------- |
20
|
|
|
*/ |
21
|
|
|
/** |
22
|
|
|
* The attributes that should be hidden for arrays. |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected $hidden = ['token']; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Indicates if the model should be timestamped. |
30
|
|
|
* |
31
|
|
|
* @var bool |
32
|
|
|
*/ |
33
|
|
|
public $timestamps = false; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The attributes that should be mutated to dates. |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $dates = [self::CREATED_AT]; |
41
|
|
|
|
42
|
|
|
/* ----------------------------------------------------------------- |
43
|
|
|
| Constructor |
44
|
|
|
| ----------------------------------------------------------------- |
45
|
|
|
*/ |
46
|
|
|
/** |
47
|
|
|
* Create a new Eloquent model instance. |
48
|
|
|
* |
49
|
|
|
* @param array $attributes |
50
|
|
|
*/ |
51
|
3 |
|
public function __construct(array $attributes = []) |
52
|
|
|
{ |
53
|
3 |
|
parent::__construct($attributes); |
54
|
|
|
|
55
|
3 |
|
$this->setConnection(null)->setPrefix(null); |
56
|
3 |
|
$this->setTable(config('auth.passwords.users.table', 'password_resets')); |
57
|
3 |
|
} |
58
|
|
|
|
59
|
|
|
/* ----------------------------------------------------------------- |
60
|
|
|
| Relationships |
61
|
|
|
| ----------------------------------------------------------------- |
62
|
|
|
*/ |
63
|
|
|
/** |
64
|
|
|
* The user relationship. |
65
|
|
|
* |
66
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
67
|
|
|
*/ |
68
|
|
|
public function user() |
69
|
|
|
{ |
70
|
|
|
return $this->belongsTo(User::class, 'email', 'email'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/* ----------------------------------------------------------------- |
74
|
|
|
| Getters & Setters |
75
|
|
|
| ----------------------------------------------------------------- |
76
|
|
|
*/ |
77
|
|
|
/** |
78
|
|
|
* Get the token repository. |
79
|
|
|
* |
80
|
|
|
* @return \Illuminate\Auth\Passwords\TokenRepositoryInterface |
81
|
|
|
*/ |
82
|
|
|
public static function getTokenRepository() |
83
|
|
|
{ |
84
|
|
|
return app('auth.password')->getRepository(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/* ----------------------------------------------------------------- |
88
|
|
|
| Check Methods |
89
|
|
|
| ----------------------------------------------------------------- |
90
|
|
|
*/ |
91
|
|
|
/** |
92
|
|
|
* Check if the password reset was expired. |
93
|
|
|
* |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
|
|
public function isExpired() |
97
|
|
|
{ |
98
|
|
|
return $this->created_at->lt( |
99
|
|
|
Carbon::now()->subMinutes(config('auth.passwords.users.expire', 60)) |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|