[英]Can't resolve route - basic login
so I'm currently looking into Neos CMS and wanted to create a very basic login logic. 所以我目前正在研究Neos CMS,并希望创建一个非常基本的登录逻辑。 [for practice] [练习]
I basically followed: http://flowframework.readthedocs.io/en/stable/TheDefinitiveGuide/PartIII/Security.html#authentication 我基本上遵循: http : //flowframework.readthedocs.io/en/stable/TheDefinitiveGuide/PartIII/Security.html#authentication
My Code: [neos/ being the root dir] 我的代码:[neos /是根目录]
Routes: [neos/Configuration/Routes.yaml] Note that's what I added in the beginning of the file, not the whole content of the file. 路由: [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/] 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/] 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/] 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/] 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/] 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/] ** 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'
}
Problem: if I call: www.neos.dev/authenticate I get: 问题:如果我致电:www.neos.dev/authenticate,我得到:
Validation failed while trying to call VMP\Auth\Controller\AuthenticationController->authenticateAction().
So I think, the route itself does work. 所以我认为,路线本身确实可行。 I now added the login form of my VMP.Auth Plugin to some page and logged in (with an existing user). 现在,我将VMP.Auth插件的登录表单添加到某个页面并使用现有用户登录。 The login form uses /authenticate as its action, but now I get the following error: 登录表单使用/ 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.
I don't really know what's the issue here. 我真的不知道这是什么问题。 I guess my routing is wrong but I can't see it. 我想我的路由错误,但是看不到。
your onAuthenticationSuccess
method has: 您的onAuthenticationSuccess
方法具有:
$this->redirect('someDefaultActionAfterLogin');
which is probably triggered (correctly) now. 现在可能已经(正确)触发了。 That tries to redirect to an action someDefaultActionAfterLoginAction
in your AuthenticationController
but this action does not exist. 尝试将其重定向到AuthenticationController
someDefaultActionAfterLoginAction
操作,但此操作不存在。 For starters try $this->redirectToUri('/')
to just have a redirect to the homepage. 对于初学者来说,尝试$this->redirectToUri('/')
只是将其重定向到首页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.