Remove event dispatcher explicit usage

This commit is contained in:
Lance Pioch 2024-03-19 16:14:24 -04:00
parent 1d96ed8869
commit 44b9eb2358
6 changed files with 5 additions and 47 deletions

View File

@ -1,16 +0,0 @@
<?php
namespace App\Extensions\Illuminate\Database\Eloquent;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
class Builder extends EloquentBuilder
{
/**
* Do nothing.
*/
public function search(): self
{
return $this;
}
}

View File

@ -1,10 +0,0 @@
<?php
namespace App\Extensions\Illuminate\Events\Contracts;
use Illuminate\Contracts\Events\Dispatcher;
interface SubscribesToEvents
{
public function subscribe(Dispatcher $events): void;
}

View File

@ -8,7 +8,7 @@ use Illuminate\Http\Request;
use App\Models\User; use App\Models\User;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use App\Facades\Activity; use App\Facades\Activity;
use Illuminate\Contracts\View\View; use Illuminate\View\View;
class LoginController extends AbstractLoginController class LoginController extends AbstractLoginController
{ {

View File

@ -8,7 +8,6 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Contracts\Hashing\Hasher; use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Support\Facades\Password; use Illuminate\Support\Facades\Password;
use Illuminate\Auth\Events\PasswordReset; use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Contracts\Events\Dispatcher;
use App\Exceptions\DisplayException; use App\Exceptions\DisplayException;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Foundation\Auth\ResetsPasswords;
@ -29,7 +28,6 @@ class ResetPasswordController extends Controller
* ResetPasswordController constructor. * ResetPasswordController constructor.
*/ */
public function __construct( public function __construct(
private Dispatcher $dispatcher,
private Hasher $hasher, private Hasher $hasher,
) { ) {
} }
@ -78,7 +76,7 @@ class ResetPasswordController extends Controller
$user->setRememberToken(Str::random(60)); $user->setRememberToken(Str::random(60));
$user->save(); $user->save();
$this->dispatcher->dispatch(new PasswordReset($user)); event(new PasswordReset($user));
// If the user is not using 2FA log them in, otherwise skip this step and force a // If the user is not using 2FA log them in, otherwise skip this step and force a
// fresh login where they'll be prompted to enter a token. // fresh login where they'll be prompted to enter a token.

View File

@ -6,18 +6,10 @@ use GuzzleHttp\Client;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use App\Events\Auth\FailedCaptcha; use App\Events\Auth\FailedCaptcha;
use Illuminate\Contracts\Events\Dispatcher;
use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
class VerifyReCaptcha class VerifyReCaptcha
{ {
/**
* VerifyReCaptcha constructor.
*/
public function __construct(private Dispatcher $dispatcher)
{
}
/** /**
* Handle an incoming request. * Handle an incoming request.
*/ */
@ -45,12 +37,7 @@ class VerifyReCaptcha
} }
} }
$this->dispatcher->dispatch( event(new FailedCaptcha($request->ip(), $result->hostname ?? null));
new FailedCaptcha(
$request->ip(),
!empty($result) ? ($result->hostname ?? null) : null
)
);
throw new HttpException(Response::HTTP_BAD_REQUEST, 'Failed to validate reCAPTCHA data.'); throw new HttpException(Response::HTTP_BAD_REQUEST, 'Failed to validate reCAPTCHA data.');
} }

View File

@ -5,10 +5,9 @@ namespace App\Listeners\Auth;
use App\Facades\Activity; use App\Facades\Activity;
use Illuminate\Auth\Events\Failed; use Illuminate\Auth\Events\Failed;
use App\Events\Auth\DirectLogin; use App\Events\Auth\DirectLogin;
use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Events\Dispatcher;
use App\Extensions\Illuminate\Events\Contracts\SubscribesToEvents;
class AuthenticationListener implements SubscribesToEvents class AuthenticationListener
{ {
/** /**
* Handles an authentication event by logging the user and information about * Handles an authentication event by logging the user and information about