0
我试图在用户可以使用其用户名或电子邮件地址的情况下实现登录功能。我已经用两种方法制定了登录,但是当用户使用他的电子邮件地址成功登录时,authError仍然闪烁(用户登录)。我已经在登录操作中发表了“HERE”的评论,并且我不确定在重定向之后会发生什么。CakePHP 1.3:在成功登录时获取authError消息
这里是我的代码的相关位:
应用Controoler:
public $components = array(
'Auth' => array(
'authorize' => 'controller',
'loginRedirect' => array(
'controller' => 'users',
'action' => 'welcome_page'
),
'loginError' => 'Invalid user name/password',
'authError' => 'You don\'t have permission'
),
'Session',
);
用户控制器:
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add');
}
public function login() {
// At this point, the Auth Component is unable to log in user, so check with email.
if (!empty($this->data) &&
!empty($this->Auth->data['User']['username']) &&
!empty($this->Auth->data['User']['password'])) {
// Look for user with email address using the entered username
$user = $this->User->find('first', array(
'conditions' => array(
'User.email' => $this->Auth->data['User']['username'],
'User.password' => $this->Auth->data['User']['password']
),
'recursive' => -1
));
// Check if a matching user is found and that if login was succesfull
if (!empty($user) && $this->Auth->login($user)) {
if ($this->Auth->autoRedirect) {
// NOTE: user trying to log in with email reaches HERE
$this->redirect($this->Auth->redirect()); // this is the default authentication redirect defined in App Controller
}
} else {
$this->Session->setFlash($this->Auth->loginError, $this->Auth->flashElement, array(), 'auth');
}
}
}
的AuthMessage存储在会话内,并且将示出其使用'回声$这 - >会话级>闪光()后从会话中删除;'。当登录失败时,您是否有可能在登录页面上显示该消息,因此未成功登录的消息未被清除? – thaJeztah 2013-03-24 19:39:06