66use stdClass ;
77use GuzzleHttp \Client ;
88use Illuminate \Http \Request ;
9+ use Illuminate \Http \Response ;
910use Pterodactyl \Events \Auth \FailedCaptcha ;
1011use Illuminate \Contracts \Config \Repository ;
12+ use Illuminate \Contracts \Events \Dispatcher ;
13+ use Symfony \Component \HttpKernel \Exception \HttpException ;
1114
1215class VerifyReCaptcha
1316{
@@ -16,14 +19,21 @@ class VerifyReCaptcha
1619 */
1720 private $ config ;
1821
22+ /**
23+ * @var \Illuminate\Contracts\Events\Dispatcher
24+ */
25+ private $ dispatcher ;
26+
1927 /**
2028 * VerifyReCaptcha constructor.
2129 *
30+ * @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
2231 * @param \Illuminate\Contracts\Config\Repository $config
2332 */
24- public function __construct (Repository $ config )
33+ public function __construct (Dispatcher $ dispatcher , Repository $ config )
2534 {
2635 $ this ->config = $ config ;
36+ $ this ->dispatcher = $ dispatcher ;
2737 }
2838
2939 /**
@@ -57,10 +67,15 @@ public function handle($request, Closure $next)
5767 }
5868 }
5969
60- // Emit an event and return to the previous view with an error (only the captcha error will be shown!)
61- event (new FailedCaptcha ($ request ->ip (), (! isset ($ result ) ?: object_get ($ result , 'hostname ' ))));
70+ $ this ->dispatcher ->dispatch (
71+ new FailedCaptcha (
72+ $ request ->ip (), ! empty ($ result ) ? ($ result ->hostname ?? null ) : null
73+ )
74+ );
6275
63- return redirect ()->back ()->withErrors (['g-recaptcha-response ' => trans ('strings.captcha_invalid ' )])->withInput ();
76+ throw new HttpException (
77+ Response::HTTP_BAD_REQUEST , 'Failed to validate reCAPTCHA data. '
78+ );
6479 }
6580
6681 /**
0 commit comments