Мои пользователи должны подтвердить свои адреса электронной почты, прежде чем они получат доступ к приложению.
У меня есть определенный маршрут, по которому они отправляются, если они входят в систему, а их электронная почта не подтверждена: «клиент / регистрация-посадка», это отправит электронное письмо, и представление объяснит, что им нужно делать.
Я использую бутстрап для краткости.
Это то, что у меня есть до сих пор, и последнее, что я изо всех сил пытаюсь решить (часть перенаправления)
//I run console related queries and this breaks if run
if ( $e->getRequest() instanceof \ZF\ContentNegotiation\Request )
{
//Get a user object
$authService = $sm->get( AuthorizationService::class );
$userObject = $authService->getIdentity();
if (!$userObject instanceof User ) {
return;
}
if ($userObject->getIsEmailConfirmed() == 1) {
return;
}
//So we have a logged in user who needs to confirm their email
$redirect = $em->attach(MvcEvent::EVENT_DISPATCH,
function($e){
$route = $e->getRouteMatch();
if ($route->getMatchedRouteName() != 'customer/register-landing')
{
//Redirect to the route: customer/register-landing
}
}
);
}
Что мне нужно сделать, чтобы перенаправить на реальную страницу? Я осмотрелся и нашел этот код:
$em->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
$controller = $e->getTarget();
$controller->plugin('redirect')->toRoute('customer/register-landing');
}, 100);
Однако, когда я добавляю его в класс, он не работает:
$redirect = $em->attach(MvcEvent::EVENT_DISPATCH,
function($e){
$route = $e->getRouteMatch();
if ($route->getMatchedRouteName() != 'customer/register-landing')
{
$em->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
$controller = $e->getTarget();
$controller->plugin('redirect')->toRoute('customer/register-landing');
}, 100);
}
}
);
Каков правильный способ сделать это?