本文介绍了认证不工作时用户存储在替换表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有CakePHP2的认证系统,用户存储在数据库表中的发展问题参与者
(不是用户
像往常一样)。
I have problems with development of CakePHP2's authentication system, where users are stored in database table participants
(not users
, like usual).
这根本不进行身份验证的参与者。
It simply does not authenticate participant.
表参与者
旁边结构:
CREATE TABLE IF NOT EXISTS `participants` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`confirmed` tinyint(1) NOT NULL DEFAULT '0',
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`password` char(40) COLLATE utf8_unicode_ci DEFAULT NULL,
`token` char(32) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
)
文件AppController.php有这样的内容:
File AppController.php have content like this:
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array('Cookie', 'Session', 'Auth');
function beforeFilter() {
$this->Auth->userModel = 'Participant';
$this->Auth->fields = array('username' => 'name', 'password' => 'password');
$this->Auth->loginAction = array('controller' => 'participants', 'action' => 'login');
//$this->Auth->logoutRedirect = array('controller' => 'participants', 'action' => 'logout'); // i will use this later
//$this->Auth->loginRedirect = array('controller' => 'participants', 'action' => 'index');
}
}
文件ParticipantsController.php有内容,如:
File ParticipantsController.php have content like:
App::uses('AppController', 'Controller');
class ParticipantsController extends AppController {
function beforeFilter() {
parent::beforeFilter();
$this->Auth->allowedActions = array('registration', 'login', 'forgotten', 'recreate', 'confirm');
}
function login() {
if ($this->Auth->login()) {
$this->redirect(array('controller' => 'participants', 'action'=>'view'));
} else {
// it always end-up here
//pr($this->data);
//pr(AuthComponent::password($this->data['Participant']['password']));
//exit;
$this->Session->setFlash( __('Error, please try again.', true) );
}
}
我不知道什么是错在这里,你可以请帮我什么,我在这里丢失?
I don't know what is wrong here, can you please help me what I'm missing here?
推荐答案
我想可能是你的域和的usermodel配置
I think it might be your configuration of fields and userModel
$这个 - > Auth->田
我的工作code是接近:
My working code is closer to :
$this->Auth->authenticate = array(
'Form' => array('userModel' => 'Participant'
, 'fields' => array('username' => 'name', 'password' => 'password')
)
);
这篇关于认证不工作时用户存储在替换表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!