我是cakephp的新手。我在cakephp 2.x中制作了一个记录系统..我被困在这里
UsersController.php 扩展AppController
public function login()
{
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Your email/password combination was incorrect');
}
}
}
问题是它没有检查用户输入的电子邮件和密码是否正确..并且正在记录用户而没有检查..我以前从未使用过auth组件...所以我我很难理解这个功能如何检查数据库中的电子邮件和密码,如互联网和cakephp网站,他们正在使用此功能来检查用户是否已成功登录./i总是使用sql查询但是我不知道这个组件是如何工作的..请更正此功能并解释我从数据库中检查电子邮件和密码的位置
这是我的 的 AppController的
class AppController extends Controller {
public $components = array(
'Session',
'Auth'=>array(
'loginRedirect'=>array('controller'=>'users', 'action'=>'admin'),
'logoutRedirect'=>array('controller'=>'users', 'action'=>'admin'),
'authError'=>"You can't access that page",
'authorize'=>array('Controller')
)
);
public function isAuthorized($user) {
}
public function beforeFilter() {
$this->Auth->allow('index');
} }
答案 0 :(得分:1)
class AppController扩展Controller {
// added the debug toolkit
// sessions support
// authorization for login and logut redirect
public $components = array(
'Session',
'Cookie',
'Auth' => array(
'authenticate' => array('Form' => array('fields' => array('username' => 'email', 'password' => 'password'),)),
'authorize' => array('Controller'))
);
public function isAuthorized($user) {
return true;
}
}
请替换app in app控制器。