簡體   English   中英

無法解析路線-基本登錄

[英]Can't resolve route - basic login

所以我目前正在研究Neos CMS,並希望創建一個非常基本的登錄邏輯。 [練習]

我基本上遵循: http : //flowframework.readthedocs.io/en/stable/TheDefinitiveGuide/PartIII/Security.html#authentication

我的代碼:[neos /是根目錄]

路由: [neos / Configuration / Routes.yaml]請注意,這是我在文件開頭添加的內容,而不是文件的全部內容。

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

AuthenticationController.php [neos / Packages / Plugins / VMP.Auth / Classes / 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 / Packages / Plugins / VMP.Auth / Configuration /]

'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 / Packages / Plugins / VMP.Auth / Configuration /]

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

Index.html [neos / Packages / Plugins / VMP.Auth / Resources / Private / Templates / Authentication /]

<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 / Packages / Plugins / 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.

我真的不知道這是什么問題。 我想我的路由錯誤,但是看不到。

您的onAuthenticationSuccess方法具有:

$this->redirect('someDefaultActionAfterLogin');

現在可能已經(正確)觸發了。 嘗試將其重定向到AuthenticationController someDefaultActionAfterLoginAction操作,但此操作不存在。 對於初學者來說,嘗試$this->redirectToUri('/')只是將其重定向到首頁。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM