我正在将旧的 CakePHP 应用程序升级到 CakePHP 2.4 登录我让用户模型(称为参与者)工作以登录用户,但它还在数据库中添加了一条新记录(带有空数据)
应用控制器.php
// authorization
$this->Auth->authorize = 'controller';
$this->Auth->loginAction = array('controller' => 'participants', 'action' => 'login');
$this->Auth->userModel = 'Participant';
$this->Auth->userScope = array('Participant.validate_email' => 'yes');
$this->Auth->fields = array('username' => 'email', 'password' => 'password');
$this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'welcome');
$this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'welcome');
$this->autoRedirect = false;
$this->Auth->authenticate = array('Form' => array(
'fields' => array('username' => 'email', 'password' => 'password'),
'userModel' => 'Participant'
));
参与者控制器.php
public function login() {
if (!(empty($this->data)) && $this->Auth->login()) {
$this->log('Logged in with success', 'access');
$this->Participant->id = $this->Session->read('Auth.Participant.id');
$this->Participant->saveField('last_login', date(DATE_ATOM));
$this->redirect($this->Auth->redirect(), null, true);
}
}
Edit1:如何防止每次有人登录时创建新用户?
Edit2:会话具有正确的用户选择,并且使用虚假凭据登录也不起作用。每次登录都会触发一条新记录添加到数据库中