我是 cakephp 新手。登录时遇到问题。使用错误的名称和密码重定向到登录主页。
用户控制器.php
public function login() {
$this->layout = 'admin-login';
if ($this->request->is('post')) {
if ($this->Auth->login($this->request->data)) {
return $this->redirect($this->Auth->redirectUrl())
} else {
$this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
}
}
}
应用控制器.php
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'loginAction' => array('controller' => 'users', 'action' => 'login')
)
);
public function beforeFilter() {
$this->Auth->allow("login");
//$this->Auth->authorize = array('Controller');
$this->Auth->authenticate = array(
'Form' => array (
'scope' => array(
'User.is_active' => 1
)
)
);
}
public function isAuthorized($user) {
return true;
}
登录.ctp
echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->submit(__('Submit');
echo $this->Form->end();
当我填写错误的用户名和密码并单击提交按钮时,它会重定向到主页,谢谢。