middleware('guest:frontend'); } public function showLinkRequestForm(): View { return view('fo.auth.passwords.email'); } public function sendResetLinkEmail(Request $request, GetCustomerByEmailQuery $query): JsonResponse | RedirectResponse { $this->validateEmail($request); $shopperId = $this->executor->execute( $query, new GetCustomerByEmailQueryInput(new Email($request->string('email')->toString())), ); if (! $shopperId instanceof ShopperId) { return $this->sendResponse($request->wantsJson()); } $shopper = $this->shopperService->getShopperFor($shopperId); if (! $shopper || ! $shopper->isActive()) { return $this->sendResponse($request->wantsJson()); } return $this->traitSendResetLinkEmail($request); } protected function validateEmail(Request $request): void { $request->validate([ 'email' => [ 'bail', 'required', 'string', static function (string $attribute, mixed $value, \Closure $fail): void { try { new Email(\is_string($value) ? $value : ''); } catch (\DomainException) { $fail(__('validation.email', ['attribute' => $attribute])); } }, ], ]); } protected function sendResetLinkResponse(Request $request, string $response): JsonResponse | RedirectResponse { return $this->sendResponse($request->wantsJson()); } protected function sendResetLinkFailedResponse(Request $request, string $response): JsonResponse | RedirectResponse { return $this->sendResponse($request->wantsJson()); } protected function sendResponse(bool $wantsJson): JsonResponse | RedirectResponse { $message = trans( 'Please check your email, if we know you you should receive a reset link' ); return $wantsJson ? new JsonResponse(['message' => $message], 202) : back()->with('status', $message); } public function broker(): PasswordBroker { return Password::broker('customers'); } }