- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在登录网站的一部分。因此,我不想在 AppController 中启动身份验证,但在实际的 Controller 中我需要它。
在 PremiumController 中:
[...]
use Cake\Controller\Component\AuthComponent;
[...]
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'Basic' => ['userModel' => 'Clients'],
'Form' => ['userModel' => 'Clients'],
'loginAction' => [
'controller' => 'Premium',
'action' => 'login',
'plugin' => false
],
'authError' => 'Unauthorized Access',
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'naam',
'password' => 'pass'
],
'userModel'=>'Clients', //Other table than Users
'passwordHasher' => [
'className' => 'Premium', //use MD5
]
]
],
'loginRedirect' => [
'controller' => 'Premium',
'action' => 'dashboard'
],
'logoutRedirect' => [
'controller' => 'Search',
'action' => 'index'
]
]);
}
[...] 并降低登录部分
public function login()
{
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid username or password, try again'));
}
}
我没有得到任何结果。 $user 仍为“false”
我怎样才能做到这一点?有没有办法正确调试 Auth 组件?
最佳答案
尝试在 session 中分配 key ,以便 Auth 检查 session 中是否存在该 key 。
像这样更改你的代码,
$this->loadComponent('Auth', [
'Basic' => ['userModel' => 'Clients'],
'Form' => ['userModel' => 'Clients'],
'loginAction' => [
'controller' => 'Premium',
'action' => 'login',
'plugin' => false
],
'authError' => 'Unauthorized Access',
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'naam',
'password' => 'pass'
],
'userModel'=>'Clients', //Other table than Users
'passwordHasher' => [
'className' => 'Premium', //use MD5
]
]
],
'loginRedirect' => [
'controller' => 'Premium',
'action' => 'dashboard'
],
'logoutRedirect' => [
'controller' => 'Search',
'action' => 'index'
]
]);
$this->Auth->__set('sessionKey', 'Auth.client');
关于mysql - CakePHP 3.x 从 AppController 以外的其他 Controller 启动 Auth 组件给出错误结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45337795/
在阅读 cocoa 教程时,我注意到一些教程使用 AppDelegate 和一些 AppController 来定义打开各种窗口的 IBActions使用NSWindowController的子类。
如何在 app/app_controller.php 中调用 app_controller.php 中的函数在 app/plugins/media/models/behaviors/transfer.
在很多cakephp中的Acl组件的教程中我得到了在 AppController 或所有其他继承 AppController 的 Controller 中添加组件的指令...... 但问题是 var
我正在尝试按照本教程进行操作: https://angular.github.io/router/getting-started 为什么 AppController.$routeConfig 未定义?
我正在制作一个应用程序,该应用程序生成 JsonObjectRequest 并使用 Android 的 Volley 网络库从 URL 检索 JSON 数据。 AppController.java p
我刚改为使用 Typescript,但我一启动应用程序就收到错误消息。 这是我定义 AppController 的方式: app.controller('appController', AppCont
我正在使用 CakePHP 3。我一直在寻找使我的应用程序模块化的方法,有人建议我使用插件来做到这一点。所以我决定试一试。请看我之前的问题:Modular Directory Structure Wi
我正在尝试呈现错误模板(例如 error400.ctp),但默认布局(站点页眉和页脚)依赖于 AppController 中设置的组件和变量。我如何告诉 Cake 在呈现错误页面时使用 AppCont
我一直想知道为什么我的错误页面导致了我网站的某些页面不渲染,但后来我意识到这是因为 AppError extendsErrorHandler 而不是 AppController。这造成了一些变数我在
AppController 中未检测到 ajax 请求。 我已经打印了 params 数组。这是示例。 CakeRequest Object( [params] => Array
我将 CacheHelper 添加到我的应用程序中。在我的 APP/Config/core.php 中有 Configure::write('Cache.check', true); 在 APP/Co
我在导入 Firebase 时收到此错误“禁用模块时使用‘@import’”。 #import "GameKit/GKLocalPlayer.h" #import "GameKit/GKScore.h
我有一个名为AppController的类,我在 AppDelegate 中有以下方法,当选择菜单项时会调用该方法。 -(IBAction)selectSug:(id) sender { Ap
我使用的是 XCode 4,请注意,在设置新的 Cocoa 应用程序项目时,您会获得一个 AppDelegate.m 和 .h 文件,以及一个 .nib (.xib)。使用 alt-command-r
我正在尝试在 AppController 中对没有关联模型的表运行查询。我不想使用模型,因为这个查询会在每个请求上触发,我想使用模型会让它变慢一点。 我在一个论坛中发现,这可以通过 CakePHP 1
任何人都可以告诉我这个错误的来源是什么。我已经尝试了我在网上找到的所有解决方案,但都无济于事。我刚刚安装了一个 cakePHP 框架,但在 index.cpt 页面上出现了这个错误... 错误: fa
我目前正在为 iOS 编写 Cocos2d 游戏。 在这个游戏中,我创建了一个 GameState 单例以保存我的游戏状态(项目详细信息和位置、持续时间、分数等)。 我的主要 CCScene 包含一个
我正在为一个使用 CakePHP 2.3 的新站点编写单元测试。一切都很顺利,除了一件事。我想测试 beforeFilter() 和 beforeRender() 函数。 beforeFilter()
我想知道是否有可能在 AppController 和我的应用程序的其他 Controller 之间添加另一个抽象 Controller ? 这样我的 Controller ,例如UsersContro
我有一个功能,我希望我的所有 Controller 都能使用,所以我在 AppController 中定义了它。现在这个函数将做的部分事情与 Controller 无关,所以它应该在模型中,但由于这是
我是一名优秀的程序员,十分优秀!