@@ -17,6 +17,13 @@ class DatabaseTokenRepository implements TokenRepositoryInterface
17
17
*/
18
18
protected $ connection ;
19
19
20
+ /**
21
+ * The Hasher implementation.
22
+ *
23
+ * @var \Illuminate\Contracts\Hashing\Hasher
24
+ */
25
+ protected $ hasher ;
26
+
20
27
/**
21
28
* The token database table.
22
29
*
@@ -38,29 +45,24 @@ class DatabaseTokenRepository implements TokenRepositoryInterface
38
45
*/
39
46
protected $ expires ;
40
47
41
- /**
42
- * The hasher implementation.
43
- *
44
- * @var \Illuminate\Contracts\Hashing\Hasher
45
- */
46
- protected $ hasher ;
47
-
48
48
/**
49
49
* Create a new token repository instance.
50
50
*
51
51
* @param \Illuminate\Database\ConnectionInterface $connection
52
+ * @param \Illuminate\Contracts\Hashing\Hasher $hasher
52
53
* @param string $table
53
54
* @param string $hashKey
54
55
* @param int $expires
55
56
* @return void
56
57
*/
57
- public function __construct (ConnectionInterface $ connection , HasherContract $ hasher , $ table , $ hashKey , $ expires = 60 )
58
+ public function __construct (ConnectionInterface $ connection , HasherContract $ hasher ,
59
+ $ table , $ hashKey , $ expires = 60 )
58
60
{
59
61
$ this ->table = $ table ;
62
+ $ this ->hasher = $ hasher ;
60
63
$ this ->hashKey = $ hashKey ;
61
64
$ this ->expires = $ expires * 60 ;
62
65
$ this ->connection = $ connection ;
63
- $ this ->hasher = $ hasher ;
64
66
}
65
67
66
68
/**
@@ -115,26 +117,26 @@ protected function getPayload($email, $token)
115
117
* @param string $token
116
118
* @return bool
117
119
*/
118
- public function exists (CanResetPasswordContract $ user , $ userToken )
120
+ public function exists (CanResetPasswordContract $ user , $ token )
119
121
{
120
- $ email = $ user ->getEmailForPasswordReset ();
122
+ $ record = (array ) $ this ->getTable ()->where (
123
+ 'email ' , $ user ->getEmailForPasswordReset ()
124
+ )->first ();
121
125
122
- $ token = ( array ) $ this -> getTable ()-> where ( ' email ' , $ email )-> first ();
123
-
124
- return $ token && ! $ this -> tokenExpired ( $ token ) && $ this ->hasher ->check ($ userToken , $ token ['token ' ]);
126
+ return $ record &&
127
+ ! $ this -> tokenExpired ( $ record [ ' created_at ' ]) &&
128
+ $ this ->hasher ->check ($ token , $ record ['token ' ]);
125
129
}
126
130
127
131
/**
128
132
* Determine if the token has expired.
129
133
*
130
- * @param array $token
134
+ * @param string $createdAt
131
135
* @return bool
132
136
*/
133
- protected function tokenExpired ($ token )
137
+ protected function tokenExpired ($ createdAt )
134
138
{
135
- $ expiresAt = Carbon::parse ($ token ['created_at ' ])->addSeconds ($ this ->expires );
136
-
137
- return $ expiresAt ->isPast ();
139
+ return Carbon::parse ($ createdAt )->addSeconds ($ this ->expires )->isPast ();
138
140
}
139
141
140
142
/**
@@ -171,23 +173,23 @@ public function createNewToken()
171
173
}
172
174
173
175
/**
174
- * Begin a new database query against the table .
176
+ * Get the database connection instance .
175
177
*
176
- * @return \Illuminate\Database\Query\Builder
178
+ * @return \Illuminate\Database\ConnectionInterface
177
179
*/
178
- protected function getTable ()
180
+ public function getConnection ()
179
181
{
180
- return $ this ->connection -> table ( $ this -> table ) ;
182
+ return $ this ->connection ;
181
183
}
182
184
183
185
/**
184
- * Get the database connection instance .
186
+ * Begin a new database query against the table .
185
187
*
186
- * @return \Illuminate\Database\ConnectionInterface
188
+ * @return \Illuminate\Database\Query\Builder
187
189
*/
188
- public function getConnection ()
190
+ protected function getTable ()
189
191
{
190
- return $ this ->connection ;
192
+ return $ this ->connection -> table ( $ this -> table ) ;
191
193
}
192
194
193
195
/**
0 commit comments