Created
May 3, 2016 08:00
-
-
Save jamesfairhurst/a30f034f6aeef45fe32f17e5588c1adf to your computer and use it in GitHub Desktop.
Laravel 5.2 Queue Password Reset Email
This file contains 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 | |
namespace App; | |
use Illuminate\Auth\Passwords\PasswordBroker as IlluminatePasswordBroker; | |
class PasswordBroker extends IlluminatePasswordBroker | |
{ | |
/** | |
* Send the password reset link via e-mail in a queue | |
* | |
* @param \Illuminate\Contracts\Auth\CanResetPassword $user | |
* @param string $token | |
* @param \Closure|null $callback | |
* @return int | |
*/ | |
public function emailResetLink(\Illuminate\Contracts\Auth\CanResetPassword $user, $token, \Closure $callback = null) | |
{ | |
// We will use the reminder view that was given to the broker to display the | |
// password reminder e-mail. We'll pass a "token" variable into the views | |
// so that it may be displayed for an user to click for password reset. | |
$view = $this->emailView; | |
return $this->mailer->queue($view, compact('token', 'user'), function ($m) use ($user, $token, $callback) { | |
$m->to($user->getEmailForPasswordReset()); | |
if (! is_null($callback)) { | |
call_user_func($callback, $m, $user, $token); | |
} | |
}); | |
} | |
} |
This file contains 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 | |
namespace App; | |
use App\PasswordBroker; | |
use Illuminate\Auth\Passwords\PasswordBrokerManager as IlluminatePasswordBrokerManager; | |
class PasswordBrokerManager extends IlluminatePasswordBrokerManager | |
{ | |
/** | |
* Resolve the given broker. | |
* | |
* @param string $name | |
* @return \App\PasswordBroker | |
* | |
* @throws \InvalidArgumentException | |
*/ | |
protected function resolve($name) | |
{ | |
$config = $this->getConfig($name); | |
if (is_null($config)) { | |
throw new InvalidArgumentException("Password resetter [{$name}] is not defined."); | |
} | |
// 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 PasswordBroker( | |
$this->createTokenRepository($config), | |
$this->app['auth']->createUserProvider($config['provider']), | |
$this->app['mailer'], | |
$config['email'] | |
); | |
} | |
} |
This file contains 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 | |
namespace App\Providers; | |
use App\PasswordBrokerManager; | |
use Illuminate\Auth\Passwords\PasswordResetServiceProvider as IlluminatePasswordResetServiceProvider; | |
class PasswordResetServiceProvider extends IlluminatePasswordResetServiceProvider | |
{ | |
/** | |
* 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(); | |
}); | |
} | |
} |
// this works fine
return $this->mailer->queue($view, compact('token', 'user'), function ($m) use ($user, $token) {
$m->to($user->getEmailForPasswordReset());
});
its wrong?
Nothing wrong with that if you don't need to call a callback.
Where should put these files?
Awesome.
Checked on Laravel 5.3.
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i get this error:
Serialization of closure failed: Serialization of closure failed: Serialization of 'Closure' is not allowed
Can you help me ?