2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Fo\Auth;
|
|
|
|
|
|
2026-10-01 11:25:05 +02:00
|
|
|
use App\Contracts\Executor;
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Exceptions\CustomerNotEmployedException;
|
2026-10-01 11:25:05 +02:00
|
|
|
use App\Queries\Customers\GetCustomerByEmailQuery;
|
|
|
|
|
use App\Queries\Customers\GetCustomerByEmailQueryInput;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Domain\Models\ValueObjects\Email;
|
2026-10-01 11:25:05 +02:00
|
|
|
use Domain\Models\ValueObjects\Entities\ShopperId;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Domain\Services\ShopperService;
|
|
|
|
|
use Illuminate\Contracts\Auth\PasswordBroker;
|
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
|
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Password;
|
|
|
|
|
|
|
|
|
|
class ForgotPasswordController extends AuthController
|
|
|
|
|
{
|
|
|
|
|
use SendsPasswordResetEmails {
|
|
|
|
|
sendResetLinkEmail as traitSendResetLinkEmail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
2026-10-01 11:25:05 +02:00
|
|
|
private readonly Executor $executor,
|
|
|
|
|
private readonly ShopperService $shopperService,
|
2026-06-14 21:32:07 +02:00
|
|
|
) {
|
|
|
|
|
$this->middleware('guest:frontend');
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function showLinkRequestForm(): View
|
|
|
|
|
{
|
|
|
|
|
return view('fo.auth.passwords.email');
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-01 11:25:05 +02:00
|
|
|
public function sendResetLinkEmail(Request $request, GetCustomerByEmailQuery $query): JsonResponse | RedirectResponse
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
|
|
|
|
$this->validateEmail($request);
|
|
|
|
|
|
2026-10-01 11:25:05 +02:00
|
|
|
$shopperId = $this->executor->execute(
|
|
|
|
|
$query,
|
|
|
|
|
new GetCustomerByEmailQueryInput(new Email($request->string('email')->toString())),
|
|
|
|
|
);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
2026-10-01 11:25:05 +02:00
|
|
|
if ($shopperId instanceof ShopperId) {
|
|
|
|
|
$shopper = $this->shopperService->getShopperFor($shopperId);
|
2026-06-14 21:32:07 +02:00
|
|
|
if (! $shopper || ! $shopper->isActive()) {
|
|
|
|
|
throw new CustomerNotEmployedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->traitSendResetLinkEmail($request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
}
|