Merge pull request #1340 from clarkwinkelmann/fix-password-changed-on-reset

Dispatch user events after password reset
This commit is contained in:
Toby Zerner 2018-01-09 13:35:24 +10:30 committed by GitHub
commit b140263830

View File

@ -11,11 +11,13 @@
namespace Flarum\Forum\Controller; namespace Flarum\Forum\Controller;
use Flarum\Foundation\DispatchEventsTrait;
use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\Controller\ControllerInterface;
use Flarum\Http\SessionAuthenticator; use Flarum\Http\SessionAuthenticator;
use Flarum\Http\UrlGenerator; use Flarum\Http\UrlGenerator;
use Flarum\User\PasswordToken; use Flarum\User\PasswordToken;
use Flarum\User\UserValidator; use Flarum\User\UserValidator;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Validation\Factory; use Illuminate\Contracts\Validation\Factory;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
@ -23,6 +25,8 @@ use Zend\Diactoros\Response\RedirectResponse;
class SavePasswordController implements ControllerInterface class SavePasswordController implements ControllerInterface
{ {
use DispatchEventsTrait;
/** /**
* @var UrlGenerator * @var UrlGenerator
*/ */
@ -49,12 +53,13 @@ class SavePasswordController implements ControllerInterface
* @param UserValidator $validator * @param UserValidator $validator
* @param Factory $validatorFactory * @param Factory $validatorFactory
*/ */
public function __construct(UrlGenerator $url, SessionAuthenticator $authenticator, UserValidator $validator, Factory $validatorFactory) public function __construct(UrlGenerator $url, SessionAuthenticator $authenticator, UserValidator $validator, Factory $validatorFactory, Dispatcher $events)
{ {
$this->url = $url; $this->url = $url;
$this->authenticator = $authenticator; $this->authenticator = $authenticator;
$this->validator = $validator; $this->validator = $validator;
$this->validatorFactory = $validatorFactory; $this->validatorFactory = $validatorFactory;
$this->events = $events;
} }
/** /**
@ -88,6 +93,8 @@ class SavePasswordController implements ControllerInterface
$token->user->changePassword($password); $token->user->changePassword($password);
$token->user->save(); $token->user->save();
$this->dispatchEventsFor($token->user);
$token->delete(); $token->delete();
$session = $request->getAttribute('session'); $session = $request->getAttribute('session');