我正在研究 cakephp 2.x 。我的问题是我不想使用用户名进行日志记录..我正在从用户那里获取电子邮件和密码,并从数据库中验证此电子邮件和密码
我的数据库名称中有一个表user它有 3 个字段id,
email and
password
这是我的代码
Model
<?php
class User extends AppModel {
public $useTable = 'user';
}
?>
应用控制器
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');
用户控制器
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');
}
}
}
登录.ctp
<?php
echo $this->form->create();
echo $this->form->input('email');
echo $this->form->input('password');
echo $this->form->end('Authenticate');
?>
您可以将其配置为:
public $components = array(
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
);
也可以看看配置身份验证处理程序在食谱中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)