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