Не удается разрешить маршрут - основной логин

Поэтому я в настоящее время изучаю Neos CMS и хочу создать очень простую логику входа в систему. [для практики]

Я в основном следовал: http://flowframework.readthedocs.io/en/stable/TheDefinitiveGuide/PartIII/Security.html

Мой код: [neos/ является корневым каталогом]

Маршруты: [neos / Configuration / Routes.yaml] Обратите внимание, что это то, что я добавил в начало файла, а не все содержимое файла.

-
  name: 'Authentication'
  uriPattern: 'authenticate'
  defaults:
    '@package': 'VMP.Auth'
    '@controller': 'Authentication'
    '@action': 'authenticate'

AuthenticationController.php [neos / Пакеты / Плагины /VMP.Auth/ Классы / VMP / Auth / Controller /]

<?php
namespace VMP\Auth\Controller;

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Mvc\ActionRequest;
use TYPO3\Flow\Security\Authentication\Controller\AbstractAuthenticationController;

class AuthenticationController extends AbstractAuthenticationController {

        /**
         * Displays a login form
         *
         * @return void
         */
        public function indexAction() {
        }

        /**
         * Will be triggered upon successful authentication
         *
         * @param ActionRequest $originalRequest The request that was intercepted by the security framework, NULL if there was none
         * @return string
         */
        protected function onAuthenticationSuccess(ActionRequest $originalRequest = NULL) {
                if ($originalRequest !== NULL) {
                        $this->redirectToRequest($originalRequest);
                }
                $this->redirect('someDefaultActionAfterLogin');
        }

        /**
         * Logs all active tokens out and redirects the user to the login form
         *
         * @return void
         */
        public function logoutAction() {
                parent::logoutAction();
                $this->addFlashMessage('Logout successful');
                $this->redirect('index');
        }

        public function fooAction() {
                print "lol";
        }
}

NodeTypes.yaml [neos / Пакеты / Плагины /VMP.Auth/ Конфигурация /]

'VMP.Auth:Plugin':
  superTypes:
    'TYPO3.Neos:Plugin': TRUE
  ui:
    label: 'Auth Login Form'
    group: 'plugins'

Policy.yaml [neos / Packages / Plugins /VMP.Auth/ Configuration /]

privilegeTargets:

  'TYPO3\Flow\Security\Authorization\Privilege\Method\MethodPrivilege':

    'VMP.Auth:Plugin':
      matcher: 'method(TYPO3\Flow\Security\Authentication\Controller\AbstractAuthenticationController->(?!initialize).*Action()) || method(VMP\Auth\Controller\AuthenticationController->(?!initialize).*Action())'

roles:

  'TYPO3.Flow:Everybody':
    privileges:
      -
          # Grant any user access to the FrontendLoginLoginForm plugin
        privilegeTarget: 'VMP.Auth:Plugin'
        permission: GRANT

Settings.yaml [neos / Пакеты / Плагины /VMP.Auth/ Конфигурация /]

TYPO3:
  Neos:
    typoScript:
      autoInclude:
        'VMP.Auth': TRUE
  Flow:
    security:
      authentication:
        providers:
          'AuthAuthenticationProvider':
            provider: 'PersistedUsernamePasswordProvider'

Index.html [neos / Пакеты / Плагины /VMP.Auth/ Ресурсы / Личные / Шаблоны / Аутентификация /]

<form action="authenticate" method="post">
   <input type="text"
      name="__authentication[TYPO3][Flow][Security][Authentication][Token][UsernamePassword][username]" />
   <input type="password"        name="__authentication[TYPO3][Flow][Security][Authentication][Token][UsernamePassword][password]" />
   <input type="submit" value="Login" />
</form>

** Root.ts2 [neos / Пакеты / Плагины /VMP.Auth/Resources/TypoScript/]

prototype(VMP.Auth:Plugin) < prototype(TYPO3.Neos:Plugin)
prototype(VMP.Auth:Plugin) {
      package = 'VMP.Auth'
      controller = 'Authentication'
      action = 'index'
}

Проблема: если я позвоню: www.neos.dev/authenticate, я получу:

Validation failed while trying to call VMP\Auth\Controller\AuthenticationController->authenticateAction().

Поэтому я думаю, что сам маршрут работает. Теперь я добавил форму входа моего плагина VMP.Auth на какую-то страницу и вошел в систему (с существующим пользователем). Форма входа использует / authenticate в качестве своего действия, но теперь я получаю следующую ошибку:

Page Not Found

Sorry, the page you requested was not found.

#1301610453: Could not resolve a route and its corresponding URI for the given parameters. This may be due to referring to a not existing package / controller / action while building a link or URI. Refer to log and check the backtrace for more details.

Я действительно не знаю, в чем здесь проблема. Я предполагаю, что мой маршрут неправильный, но я не могу видеть это.

1 ответ

Ваш onAuthenticationSuccess Метод имеет:

$this->redirect('someDefaultActionAfterLogin');

который, вероятно, срабатывает (правильно) сейчас. Это пытается перенаправить на действие someDefaultActionAfterLoginAction в вашем AuthenticationController но это действие не существует. Для начала попробуй$this->redirectToUri('/') просто перенаправить на домашнюю страницу.

Другие вопросы по тегам