PasswordBroker 오버라이딩하기
Submitted by river -
등록 9 years ago - 수정 9 years ago
비밀번호 리셋에 관련된 로직은 Illuminate\Auth\Passwords\PasswordBroker
클래스에서 수행이 되는데, 이 로직을 변경하고자 한다면 다음의 방법을 사용하면 된다.
CustomPassowordBroker 생성
Illuminate\Auth\Passwords\PasswordBroker
를 오버라이딩할 클래스를 생성하고 여기에 원하는 로직을 추가한다.
App\Services\CustomPasswordBroker
<?php namespace App\Services;
use Closure;
use UnexpectedValueException;
use Illuminate\Auth\Passwords\PasswordBroker;
use Illuminate\Contracts\Auth\PasswordBroker as PasswordBrokerContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class CustomPasswordBroker extends PasswordBroker
{
...
}
CustomPasswordResetServiceProvider 생성
PasswordResetServiceProvider
을 확장한 CustomPasswordResetServiceProvider
을 생성하고, 여기서 CustomPassowordBroker
인스턴스가 생성되도록 한다.
App\Prividers\CustomPasswordResetServiceProvider
<?php namespace App\Providers;
use App\Services\CustomPasswordBroker;
use Illuminate\Auth\Passwords\PasswordResetServiceProvider;
class CustomPasswordResetServiceProvider extends PasswordResetServiceProvider
{
/**
* Register the password broker instance.
*
* @return void
*/
protected function registerPasswordBroker()
{
$this->app->singleton('auth.password', function ($app) {
// The password token repository is responsible for storing the email addresses
// and password reset tokens. It will be used to verify the tokens are valid
// for the given e-mail addresses. We will resolve an implementation here.
$tokens = $app['auth.password.tokens'];
$users = $app['auth']->driver()->getProvider();
$view = $app['config']['auth.password.email'];
// The password broker uses a token repository to validate tokens and send user
// password e-mails, as well as validating that password reset process as an
// aggregate service of sorts providing a convenient interface for resets.
return new CustomPasswordBroker($tokens, $users, $app['mailer'], $view);
});
}
}
config/app.php 수정
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class
을 App\Providers\CustomPasswordResetServiceProvider::class
로 변경한다.
config/app.php
'providers' => [
...
App\Providers\CustomPasswordResetServiceProvider::class,
...
],
Stats
-
0 likes
- 4195 views