Shopware 6 – AuthControllerDecorator 已弃用

huangapple go评论78阅读模式
英文:

Shopware 6 - AuthControllerDecorator is deprecated

问题

我目前正在开发一个Shopware插件,用于在注册页面中展示登录页面。实现已经正常运行。

然而,我遇到了一个问题,Shopware指出Auth Controller已被内部化,不再可访问。我正在寻找一个可用于此目的的替代类。

您可以建议一个可用于替代Auth Controller的替代类吗?

<?php declare(strict_types=1);
...

/**
 * @RouteScope(scopes={"storefront"})
 */
class AuthControllerDecorator extends AuthController 
{
    private AuthController $decoratedAuthController;
    private AccountLoginPageLoader $loginPageLoader;
    private AbstractSendPasswordRecoveryMailRoute $sendPasswordRecoveryMailRoute;
    private AbstractResetPasswordRoute $resetPasswordRoute;
    private AbstractLoginRoute $loginRoute;
    private AbstractLogoutRoute $logoutRoute;
    private StorefrontCartFacade $cartFacade;
    private AccountRecoverPasswordPageLoader $recoverPasswordPageLoader;
    private SalesChannelContextServiceInterface $salesChannelContext;

    public function __construct(
        AuthController $decoratedAuthController,
        AccountLoginPageLoader $loginPageLoader,
        AbstractSendPasswordRecoveryMailRoute $sendPasswordRecoveryMailRoute,
        AbstractResetPasswordRoute $resetPasswordRoute,
        AbstractLoginRoute $loginRoute,
        AbstractLogoutRoute $logoutRoute,
        StorefrontCartFacade $cartFacade,
        AccountRecoverPasswordPageLoader $recoverPasswordPageLoader,
        SalesChannelContextServiceInterface $salesChannelContextService
    ) {
        $this->decoratedAuthController = $decoratedAuthController;
        $this->loginPageLoader = $loginPageLoader;

        parent::__construct(
            $this->loginPageLoader = $loginPageLoader,
            $this->sendPasswordRecoveryMailRoute = $sendPasswordRecoveryMailRoute,
            $this->resetPasswordRoute = $resetPasswordRoute,
            $this->loginRoute = $loginRoute,
            $this->logoutRoute = $logoutRoute,
            $this->cartFacade = $cartFacade,
            $this->recoverPasswordPageLoader = $recoverPasswordPageLoader,
            $this->salesChannelContextService = $salesChannelContextService
        );
        
    }

    /**
     * @Route("/account/login", name="frontend.account.login.page", methods={"GET"})
     */
    public function loginPage(Request $request, RequestDataBag $data, SalesChannelContext $context): Response
    {
        /** @var string $redirect */
        $redirect = $request->get('redirectTo', 'frontend.account.home.page');

        $customer = $context->getCustomer();

        if ($customer !== null && $customer->getGuest() === false) {
            $request->request->set('redirectTo', $redirect);

            return $this->createActionResponse($request);
        }

        $page = $this->loginPageLoader->load($request, $context);

        return $this->renderStorefront('@Storefront/storefront/page/account/login/index.html.twig', [
            'redirectTo' => $redirect,
            'redirectParameters' => $request->get('redirectParameters', json_encode([])),
            'page' => $page,
            'loginError' => (bool) $request->get('loginError'),
            'waitTime' => $request->get('waitTime'),
            'errorSnippet' => $request->get('errorSnippet'),
            'data' => $data,
        ]);
    }
}
英文:

I am currently developing a Shopware plugin to showcase the login page from the register page. The implementation is functioning correctly.

However, I have encountered an issue where Shopware indicates that the Auth Controller has been made internal and is no longer accessible. I am seeking an alternative class that can be utilized for this purpose.

Could you suggest an alternative class that can be used in place of the Auth Controller?

<?php declare(strict_types=1);
...

/**
 * @RouteScope(scopes={"storefront"})
 */
class AuthControllerDecorator extends AuthController 
{
    private AuthController $decoratedAuthController;
    private AccountLoginPageLoader $loginPageLoader;
    private AbstractSendPasswordRecoveryMailRoute $sendPasswordRecoveryMailRoute;
    private AbstractResetPasswordRoute $resetPasswordRoute;
    private AbstractLoginRoute $loginRoute;
    private AbstractLogoutRoute $logoutRoute;
    private StorefrontCartFacade $cartFacade;
    private AccountRecoverPasswordPageLoader $recoverPasswordPageLoader;
    private SalesChannelContextServiceInterface $salesChannelContext;

    public function __construct(
        AuthController $decoratedAuthController,
        AccountLoginPageLoader $loginPageLoader,
        AbstractSendPasswordRecoveryMailRoute $sendPasswordRecoveryMailRoute,
        AbstractResetPasswordRoute $resetPasswordRoute,
        AbstractLoginRoute $loginRoute,
        AbstractLogoutRoute $logoutRoute,
        StorefrontCartFacade $cartFacade,
        AccountRecoverPasswordPageLoader $recoverPasswordPageLoader,
        SalesChannelContextServiceInterface $salesChannelContextService
    ) {
        $this->decoratedAuthController = $decoratedAuthController;
        $this->loginPageLoader = $loginPageLoader;

        parent::__construct(
            $this->loginPageLoader = $loginPageLoader,
            $this->sendPasswordRecoveryMailRoute = $sendPasswordRecoveryMailRoute,
            $this->resetPasswordRoute = $resetPasswordRoute,
            $this->loginRoute = $loginRoute,
            $this->logoutRoute = $logoutRoute,
            $this->cartFacade = $cartFacade,
            $this->recoverPasswordPageLoader = $recoverPasswordPageLoader,
            $this->salesChannelContextService = $salesChannelContextService
        );
        
    }

    /**
     * @Route("/account/login", name="frontend.account.login.page", methods={"GET"})
     */
    public function loginPage(Request $request, RequestDataBag $data, SalesChannelContext $context): Response
    {
        /** @var string $redirect */
        $redirect = $request->get('redirectTo', 'frontend.account.home.page');

        $customer = $context->getCustomer();

        if ($customer !== null && $customer->getGuest() === false) {
            $request->request->set('redirectTo', $redirect);

            return $this->createActionResponse($request);
        }

        $page = $this->loginPageLoader->load($request, $context);

        return $this->renderStorefront('@Storefront/storefront/page/account/login/index.html.twig', [
            'redirectTo' => $redirect,
            'redirectParameters' => $request->get('redirectParameters', json_encode([])),
            'page' => $page,
            'loginError' => (bool) $request->get('loginError'),
            'waitTime' => $request->get('waitTime'),
            'errorSnippet' => $request->get('errorSnippet'),
            'data' => $data,
        ]);
    }
}

答案1

得分: 3

Storefront 控制器不应该被装饰。如果您想向页面的模板添加数据,请监听 AccountLoginPageLoadedEvent 事件并向页面添加扩展。

如果您想要实现自定义逻辑,例如在实际登录过程中,您应该装饰相应的 store-api 路由 Shopware\Core\Checkout\Customer\SalesChannel\LoginRoute,该路由被设计用来进行装饰。

英文:

Storefront controllers should not be decorated. If you want to add data to the page's template listen for AccountLoginPageLoadedEvent and add extensions to the page.

If you want to implement custom logic, e.g. on the actual login procedure, you should decorate the corresponding store-api route Shopware\Core\Checkout\Customer\SalesChannel\LoginRoute instead, which is intended to be decorated.

huangapple
  • 本文由 发表于 2023年7月3日 15:03:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76602524.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定