Last active
April 6, 2017 03:00
-
-
Save paulofreitas/e0ece17ad7847f7a8cb2e3bdc07f022a to your computer and use it in GitHub Desktop.
Rollbacks Laravel's 5.4 password reset tokens patch (PR #16850: https://github.com/laravel/framework/pull/16850)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // config/app.php | |
return [ | |
/* ... */ | |
'providers' => [ | |
/* ... */ | |
// Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, | |
App\Support\Auth\Passwords\PasswordResetServiceProvider::class, | |
/* ... */ | |
], | |
/* ... */ | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // app/Support/Auth/Passwords/DatabaseTokenRepository.php | |
namespace App\Support\Auth\Passwords; | |
use Carbon\Carbon; | |
use Illuminate\Auth\Passwords\DatabaseTokenRepository as BaseRepository; | |
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; | |
use Illuminate\Auth\Passwords\TokenRepositoryInterface as RepositoryContract; | |
class DatabaseTokenRepository extends BaseRepository implements RepositoryContract | |
{ | |
/** | |
* Build the record payload for the table. | |
* | |
* @param string $email | |
* @param string $token | |
* @return array | |
*/ | |
protected function getPayload($email, $token) | |
{ | |
return ['email' => $email, 'token' => $token, 'created_at' => new Carbon]; | |
} | |
/** | |
* Determine if a token record exists and is valid. | |
* | |
* @param \Illuminate\Contracts\Auth\CanResetPassword $user | |
* @param string $token | |
* @return bool | |
*/ | |
public function exists(CanResetPasswordContract $user, $token) | |
{ | |
$token = (array) $this->getTable() | |
->where('email', $user->getEmailForPasswordReset()) | |
->where('token', $token) | |
->first(); | |
return $token && !$this->tokenExpired($token['created_at']); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // app/Support/Auth/Passwords/PasswordBrokerManager.php | |
namespace App\Support\Auth\Passwords; | |
use Illuminate\Support\Str; | |
use Illuminate\Auth\Passwords\PasswordBrokerManager as BaseManager; | |
use Illuminate\Contracts\Auth\PasswordBrokerFactory as FactoryContract; | |
class PasswordBrokerManager extends BaseManager implements FactoryContract | |
{ | |
/** | |
* Create a token repository instance based on the given configuration. | |
* | |
* @param array $config | |
* @return \Illuminate\Auth\Passwords\TokenRepositoryInterface | |
*/ | |
protected function createTokenRepository(array $config) | |
{ | |
$key = $this->app['config']['app.key']; | |
if (Str::startsWith($key, 'base64:')) { | |
$key = base64_decode(substr($key, 7)); | |
} | |
$connection = isset($config['connection']) ? $config['connection'] : null; | |
return new DatabaseTokenRepository( | |
$this->app['db']->connection($connection), | |
$this->app['hash'], | |
$config['table'], | |
$key, | |
$config['expire'] | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // app/Support/Auth/Passwords/PasswordResetServiceProvider.php | |
namespace App\Support\Auth\Passwords; | |
use Illuminate\Auth\Passwords\PasswordResetServiceProvider as BaseProvider; | |
class PasswordResetServiceProvider extends BaseProvider | |
{ | |
/** | |
* 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(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment