Skip to content

Commit

Permalink
cleaning and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 19, 2016
1 parent 7e1a230 commit 9d674b0
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class DatabaseTokenRepository implements TokenRepositoryInterface
*/
protected $connection;

/**
* The Hasher implementation.
*
* @var \Illuminate\Contracts\Hashing\Hasher
*/
protected $hasher;

/**
* The token database table.
*
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 9d674b0

Please sign in to comment.