*/ final class ResetCustomerPassword implements Action { public function __construct( private readonly ShopperService $shopperService, private readonly AppCustomerAuthService $authService, ) { } /** * @param \App\Cqs\Actions\Auth\ResetCustomerPasswordInput $input */ #[\Override] public function __invoke(ActionInput $input): ResetCustomerPasswordOutput { Assert::isInstanceOf($input, ResetCustomerPasswordInput::class); $shopper = $this->shopperService->getShopperFor($input->customer->getId()); if (! $shopper || ! $shopper->isActive()) { return ResetCustomerPasswordOutput::notEmployed(); } $result = $this->authService->resetPasswordFor($input->customer, $input->password); if ($result instanceof ValidationException) { return ResetCustomerPasswordOutput::invalidPassword($result->getMessage()); } $input->customer->setRememberToken(Str::random(60)); $input->customer->saveOrFail(); return ResetCustomerPasswordOutput::success( $this->authService->hasVerifiedEmail($input->customer) ); } }