From 9d674b053145968ff9060b930a644ddd7851d66f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 19 Dec 2016 07:41:12 -0600 Subject: [PATCH] cleaning and formatting --- .../Passwords/DatabaseTokenRepository.php | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php b/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php index 7ad0d0fcee9e..d842b6923b8f 100755 --- a/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php +++ b/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php @@ -17,6 +17,13 @@ class DatabaseTokenRepository implements TokenRepositoryInterface */ protected $connection; + /** + * The Hasher implementation. + * + * @var \Illuminate\Contracts\Hashing\Hasher + */ + protected $hasher; + /** * The token database table. * @@ -38,29 +45,24 @@ class DatabaseTokenRepository implements TokenRepositoryInterface */ protected $expires; - /** - * The hasher implementation. - * - * @var \Illuminate\Contracts\Hashing\Hasher - */ - protected $hasher; - /** * Create a new token repository instance. * * @param \Illuminate\Database\ConnectionInterface $connection + * @param \Illuminate\Contracts\Hashing\Hasher $hasher * @param string $table * @param string $hashKey * @param int $expires * @return void */ - public function __construct(ConnectionInterface $connection, HasherContract $hasher, $table, $hashKey, $expires = 60) + public function __construct(ConnectionInterface $connection, HasherContract $hasher, + $table, $hashKey, $expires = 60) { $this->table = $table; + $this->hasher = $hasher; $this->hashKey = $hashKey; $this->expires = $expires * 60; $this->connection = $connection; - $this->hasher = $hasher; } /** @@ -115,26 +117,26 @@ protected function getPayload($email, $token) * @param string $token * @return bool */ - public function exists(CanResetPasswordContract $user, $userToken) + public function exists(CanResetPasswordContract $user, $token) { - $email = $user->getEmailForPasswordReset(); + $record = (array) $this->getTable()->where( + 'email', $user->getEmailForPasswordReset() + )->first(); - $token = (array) $this->getTable()->where('email', $email)->first(); - - return $token && ! $this->tokenExpired($token) && $this->hasher->check($userToken, $token['token']); + return $record && + ! $this->tokenExpired($record['created_at']) && + $this->hasher->check($token, $record['token']); } /** * Determine if the token has expired. * - * @param array $token + * @param string $createdAt * @return bool */ - protected function tokenExpired($token) + protected function tokenExpired($createdAt) { - $expiresAt = Carbon::parse($token['created_at'])->addSeconds($this->expires); - - return $expiresAt->isPast(); + return Carbon::parse($createdAt)->addSeconds($this->expires)->isPast(); } /** @@ -171,23 +173,23 @@ public function createNewToken() } /** - * Begin a new database query against the table. + * Get the database connection instance. * - * @return \Illuminate\Database\Query\Builder + * @return \Illuminate\Database\ConnectionInterface */ - protected function getTable() + public function getConnection() { - return $this->connection->table($this->table); + return $this->connection; } /** - * Get the database connection instance. + * Begin a new database query against the table. * - * @return \Illuminate\Database\ConnectionInterface + * @return \Illuminate\Database\Query\Builder */ - public function getConnection() + protected function getTable() { - return $this->connection; + return $this->connection->table($this->table); } /**