Completed
Push — master ( f8a22c...480ba6 )
by ARCANEDEV
12s
created

PasswordReset::user()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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