Skip to content

Commit

Permalink
Fix auth for L5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Feb 12, 2016
1 parent d425493 commit 6e9b5f4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php namespace Jenssegers\Mongodb\Auth;

use DateTime;
use Illuminate\Auth\Passwords\DatabaseTokenRepository as BaseDatabaseTokenRepository;
use MongoDate;

class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRepository
class DatabaseTokenRepository extends BaseDatabaseTokenRepository
{
/**
* Build the record payload for the table.
Expand All @@ -28,9 +29,7 @@ protected function tokenExpired($token)
// Convert MongoDate to a date string.
if ($token['created_at'] instanceof MongoDate) {
$date = new DateTime;

$date->setTimestamp($token['created_at']->sec);

$token['created_at'] = $date->format('Y-m-d H:i:s');
} elseif (is_array($token['created_at']) and isset($token['created_at']['date'])) {
$token['created_at'] = $token['created_at']['date'];
Expand Down
22 changes: 22 additions & 0 deletions src/Jenssegers/Mongodb/Auth/PasswordBrokerManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php namespace Jenssegers\Mongodb\Auth;

use Illuminate\Auth\Passwords\PasswordBrokerManager as BasePasswordBrokerManager;

class PasswordBrokerManager extends BasePasswordBrokerManager
{
/**
* Create a token repository instance based on the given configuration.
*
* @param array $config
* @return \Illuminate\Auth\Passwords\TokenRepositoryInterface
*/
protected function createTokenRepository(array $config)
{
return new DatabaseTokenRepository(
$this->app['db']->connection(),
$config['table'],
$this->app['config']['app.key'],
$config['expire']
);
}
}
24 changes: 21 additions & 3 deletions src/Jenssegers/Mongodb/Auth/PasswordResetServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php namespace Jenssegers\Mongodb\Auth;

use Jenssegers\Mongodb\Auth\DatabaseTokenRepository as DbRepository;
use Illuminate\Auth\Passwords\PasswordResetServiceProvider as BasePasswordResetServiceProvider;

class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordResetServiceProvider
class PasswordResetServiceProvider extends BasePasswordResetServiceProvider
{
/**
* Register the token repository implementation.
Expand All @@ -18,10 +18,28 @@ protected function registerTokenRepository()
// interface, and is responsible for the actual storing of auth tokens and
// their e-mail addresses. We will inject this table and hash key to it.
$table = $app['config']['auth.password.table'];

$key = $app['config']['app.key'];

$expire = $app['config']->get('auth.password.expire', 60);

return new DbRepository($connection, $table, $key, $expire);
return new DatabaseTokenRepository($connection, $table, $key, $expire);
});
}

/**
* Register the password broker instance.
*
* @return void
*/
protected function registerPasswordBroker()
{
$this->app->singleton('auth.password', function ($app) {
return new PasswordBrokerManager($app);
});

$this->app->bind('auth.password.broker', function ($app) {
return $app->make('auth.password')->broker();
});
}
}

0 comments on commit 6e9b5f4

Please sign in to comment.