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