英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论