Skip to content

Commit

Permalink
Merge pull request #1352 from nolanle/master
Browse files Browse the repository at this point in the history
Fixed Error "Cannot use object of type MongoDB\BSON\UTCDateTime as array"
  • Loading branch information
jenssegers committed Apr 26, 2018
2 parents e1c6e53 + 5c2b99e commit c33fc4e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
18 changes: 9 additions & 9 deletions src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ class DatabaseTokenRepository extends BaseDatabaseTokenRepository
*/
protected function getPayload($email, $token)
{
return ['email' => $email, 'token' => $token, 'created_at' => new UTCDateTime(time() * 1000)];
return ['email' => $email, 'token' => $this->hasher->make($token), 'created_at' => new UTCDateTime(time() * 1000)];
}

/**
* @inheritdoc
*/
protected function tokenExpired($token)
protected function tokenExpired($createdAt)
{
// Convert UTCDateTime to a date string.
if ($token['created_at'] instanceof UTCDateTime) {
$date = $token['created_at']->toDateTime();
if ($createdAt instanceof UTCDateTime) {
$date = $createdAt->toDateTime();
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
$token['created_at'] = $date->format('Y-m-d H:i:s');
} elseif (is_array($token['created_at']) && isset($token['created_at']['date'])) {
$date = new DateTime($token['created_at']['date'], new DateTimeZone(isset($token['created_at']['timezone']) ? $token['created_at']['timezone'] : 'UTC'));
$createdAt = $date->format('Y-m-d H:i:s');
} elseif (is_array($createdAt) and isset($createdAt['date'])) {
$date = new DateTime($createdAt['date'], new DateTimeZone(isset($createdAt['timezone']) ? $createdAt['timezone'] : 'UTC'));
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
$token['created_at'] = $date->format('Y-m-d H:i:s');
$createdAt = $date->format('Y-m-d H:i:s');
}

return parent::tokenExpired($token);
return parent::tokenExpired($createdAt);
}
}
30 changes: 14 additions & 16 deletions src/Jenssegers/Mongodb/Auth/PasswordBrokerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@ class PasswordBrokerManager extends BasePasswordBrokerManager
*/
protected function createTokenRepository(array $config)
{
$laravel = app();

if (version_compare($laravel::VERSION, '5.4', '>=')) {
return new DatabaseTokenRepository(
$this->app['db']->connection(),
$this->app['hash'],
$config['table'],
$this->app['config']['app.key'],
$config['expire']
);
} else {
return new DatabaseTokenRepository(
$this->app['db']->connection(),
$config['table'],
$this->app['config']['app.key'],
$config['expire']
);
$key = $this->app['config']['app.key'];

if (\Illuminate\Support\Str::startsWith($key, 'base64:')) {
$key = base64_decode(substr($key, 7));
}

$connection = isset($config['connection']) ? $config['connection'] : null;

return new DatabaseTokenRepository(
$this->app['db']->connection(),
$this->app['hash'],
$config['table'],
$this->app['config']['app.key'],
$config['expire']
);
}
}

0 comments on commit c33fc4e

Please sign in to comment.