Skip to content

Commit

Permalink
fix: RequestPasswordReset is no longer available from Flarum 1.6 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland authored Sep 22, 2023
1 parent e2937fc commit 716e11c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
],
"require": {
"flarum/core": "^1.2",
"flarum/core": "^1.6",
"guzzlehttp/guzzle": "6.* || 7.*"
},
"replace": {
Expand Down
20 changes: 10 additions & 10 deletions src/Middleware/CheckLoginPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

use Flarum\Http\AccessToken;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\Command\RequestPasswordReset;
use Flarum\User\Job\RequestPasswordResetJob;
use FoF\PwnedPasswords\Events\PwnedPasswordDetected;
use FoF\PwnedPasswords\Password;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
use Illuminate\Contracts\Queue\Queue;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -27,11 +27,6 @@

class CheckLoginPassword implements MiddlewareInterface
{
/**
* @var Dispatcher
*/
private $bus;

/**
* @var SettingsRepositoryInterface
*/
Expand All @@ -42,11 +37,16 @@ class CheckLoginPassword implements MiddlewareInterface
*/
private $events;

public function __construct(Dispatcher $bus, SettingsRepositoryInterface $settings, EventDispatcher $events)
/**
* @var Queue
*/
private $queue;

public function __construct(SettingsRepositoryInterface $settings, EventDispatcher $events, Queue $queue)
{
$this->bus = $bus;
$this->settings = $settings;
$this->events = $events;
$this->queue = $queue;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
Expand All @@ -70,7 +70,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$actor = $token->user;

if ($actor && !$actor->has_pwned_password && Arr::has($data, 'password') && Password::isPwned($data['password'])) {
$this->bus->dispatch(new RequestPasswordReset($actor->email));
$this->queue->push(new RequestPasswordResetJob($actor->email));
$actor->has_pwned_password = true;
$actor->save();
$this->events->dispatch(new PwnedPasswordDetected($actor, 'login'));
Expand Down

0 comments on commit 716e11c

Please sign in to comment.