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