php - 在cakephp中登录不正确,即使一切都是正确的
问题描述
我是 CakePHP 的新手,这是一个了不起的 PHP 框架 我正在尝试构建一个新的应用程序,所以我进入了登录页面的一部分,这是我尝试登录时的代码
应用控制器
public function beforeFilter(Event $event) {
$this->Auth->allow('display');
}
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler', [
'enableBeforeRedirect' => false,
]);
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => ' email',
'password' => 'password'
]
]
],
'loginAction' => [
'controller' => 'user',
'action' => 'login'
]
]);
/*
* Enable the following component for recommended CakePHP security settings.
* see https://book.cakephp.org/3.0/en/controllers/components/security.html
*/
//$this->loadComponent('Security');
}
}
//用户控制器
public function login(){
if($this->request->is('post')){
$user = $this->Auth->identify();
if($user){
$this->Auth->setUser($user);
return $this->redirect(['controller' => 'reference']);
}
// Bad Login
$this->Flash->error('Incorrect Login');
}
}
// Logout
public function logout(){
$this->Flash->success('You are logged out');
return $this->redirect($this->Auth->logout());
}
//登录.ctp
<div class="users form">
<?= $this->Flash->render() ?>
<?= $this->Form->create() ?>
<fieldset>
<legend><?= __("Merci de rentrer vos nom d'utilisateur et mot de passe") ?></legend>
<?= $this->Form->control('username') ?>
<?= $this->Form->control('password') ?>
</fieldset>
<?= $this->Form->button(__('Se Connecter')); ?>
<?= $this->Form->end() ?>
</div>
解决方案
推荐阅读
- c# - Alexa.NET 无法创建提醒:无效的承载令牌
- apache-spark - 如何对 CSV 文件中的更新行运行流式查询?
- c++ - 对未使用的类模板方法的未定义引用
- python - Django 默认放置空字符串,同时期望它在 DB 列中为空
- android - 将依赖项版本升级到 17.1.2 后 AdMob 广告未突然加载
- jenkins - 使用 Groovy 在与父节点相同的节点上触发 Jenkins 作业
- c# - c#图片从来自互联网的URL到datagridview
- angular - 我们如何提取 BLOB 数据(存储为 blob 的图像)并将其显示在 Angular 2 中?
- android - 添加矢量可绘制支持的最简单方法
- javascript - iOS 上的背景滚动