Skip to content

Commit c33fc4e

Browse files
authored
Merge pull request #1352 from nolanle/master
Fixed Error "Cannot use object of type MongoDB\BSON\UTCDateTime as array"
2 parents e1c6e53 + 5c2b99e commit c33fc4e

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ class DatabaseTokenRepository extends BaseDatabaseTokenRepository
1414
*/
1515
protected function getPayload($email, $token)
1616
{
17-
return ['email' => $email, 'token' => $token, 'created_at' => new UTCDateTime(time() * 1000)];
17+
return ['email' => $email, 'token' => $this->hasher->make($token), 'created_at' => new UTCDateTime(time() * 1000)];
1818
}
1919

2020
/**
2121
* @inheritdoc
2222
*/
23-
protected function tokenExpired($token)
23+
protected function tokenExpired($createdAt)
2424
{
2525
// Convert UTCDateTime to a date string.
26-
if ($token['created_at'] instanceof UTCDateTime) {
27-
$date = $token['created_at']->toDateTime();
26+
if ($createdAt instanceof UTCDateTime) {
27+
$date = $createdAt->toDateTime();
2828
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
29-
$token['created_at'] = $date->format('Y-m-d H:i:s');
30-
} elseif (is_array($token['created_at']) && isset($token['created_at']['date'])) {
31-
$date = new DateTime($token['created_at']['date'], new DateTimeZone(isset($token['created_at']['timezone']) ? $token['created_at']['timezone'] : 'UTC'));
29+
$createdAt = $date->format('Y-m-d H:i:s');
30+
} elseif (is_array($createdAt) and isset($createdAt['date'])) {
31+
$date = new DateTime($createdAt['date'], new DateTimeZone(isset($createdAt['timezone']) ? $createdAt['timezone'] : 'UTC'));
3232
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
33-
$token['created_at'] = $date->format('Y-m-d H:i:s');
33+
$createdAt = $date->format('Y-m-d H:i:s');
3434
}
3535

36-
return parent::tokenExpired($token);
36+
return parent::tokenExpired($createdAt);
3737
}
3838
}

src/Jenssegers/Mongodb/Auth/PasswordBrokerManager.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,21 @@ class PasswordBrokerManager extends BasePasswordBrokerManager
1111
*/
1212
protected function createTokenRepository(array $config)
1313
{
14-
$laravel = app();
1514

16-
if (version_compare($laravel::VERSION, '5.4', '>=')) {
17-
return new DatabaseTokenRepository(
18-
$this->app['db']->connection(),
19-
$this->app['hash'],
20-
$config['table'],
21-
$this->app['config']['app.key'],
22-
$config['expire']
23-
);
24-
} else {
25-
return new DatabaseTokenRepository(
26-
$this->app['db']->connection(),
27-
$config['table'],
28-
$this->app['config']['app.key'],
29-
$config['expire']
30-
);
15+
$key = $this->app['config']['app.key'];
16+
17+
if (\Illuminate\Support\Str::startsWith($key, 'base64:')) {
18+
$key = base64_decode(substr($key, 7));
3119
}
20+
21+
$connection = isset($config['connection']) ? $config['connection'] : null;
22+
23+
return new DatabaseTokenRepository(
24+
$this->app['db']->connection(),
25+
$this->app['hash'],
26+
$config['table'],
27+
$this->app['config']['app.key'],
28+
$config['expire']
29+
);
3230
}
3331
}

0 commit comments

Comments
 (0)