php - CakePHP Authentication 登录动作
问题描述
我正在尝试从 CakepHP 设置新的身份验证方法。登录时,我在调试中收到缺少凭据的消息。在请求 POST 数据中,提交了电子邮件和密码字段。我错过了什么吗?
/**
* Login method
*/
public function login()
{
$result = $this->Authentication->getResult();
// regardless of POST or GET, redirect if user is logged in
if ($result->isValid()) {
$redirect = $this->request->getQuery('redirect', ['controller' => 'Pages', 'action' => 'display', 'home']);
return $this->redirect($redirect);
}
// display error if user submitted and authentication failed
if ($this->request->is(['post']) && !$result->isValid()) {
$this->Flash->error('Invalid username or password');
}
}
public function getAuthenticationService(ServerRequestInterface $request, ResponseInterface $response)
{
$service = new AuthenticationService();
$fields = [
'username' => 'email',
'password' => 'password'
];
// Load identifiers
$service->loadIdentifier('Authentication.Password', compact('fields'));
// Load the authenticators, you want session first
$service->loadAuthenticator('Authentication.Session');
$service->loadAuthenticator('Authentication.Form', [
'fields' => $fields,
'loginUrl' => '/users/login'
]);
return $service;
}
编辑:使用用户名/帖子字段编辑表单验证器选项后,我得到以下信息
错误:FAILURE_IDENTITY_NOT_FOUND
SQL 调试说记录在用户表中找到。
SELECT
Users.id AS `Users__id`,
Users.email AS `Users__email`,
Users.password AS `Users__password`,
Users.role AS `Users__role`,
Users.created AS `Users__created`,
Users.modified AS `Users__modified`
FROM
users Users
WHERE
Users.email = 'my@my.com'
LIMIT
1
用户表结构
id Primary key int(11)
email varchar(255) utf8mb4_general_ci
password varchar(255) utf8mb4_general_ci
role varchar(255)
created datetime
modified datetime
解决方案
已修复,密码为纯文本。添加了一个具有默认密码哈希的新用户。
推荐阅读
- asp.net-core-mvc - 如何从 ASP .NET Core 中的控制器更新值进度条引导程序
- windows - 无法在 windows 批处理脚本中运行 sqlplus || ORA-28040: 没有匹配的身份验证协议异常
- android - 如何使用kotlin滑动删除存储在firestore中的recyclerview项目?
- python - 使用 python 生成的 sas 令牌不适用于 azure blob
- dynamic - 动态列标题在 Power Query 中工作,但不在 Daschboard 上
- python-3.x - Xpath 上传 Pic Avatar Twitter
- kubernetes - 将 pvc 快照从一个 kubernetes 集群复制到另一个
- java - 如何在非英语系统中初始化 Gradle 项目?
- reactjs - 使用 Class 组件内的 Context 中的状态
- styled-components - 为什么样式组件会变慢?