为什么不将验证组件的用户名和放大器;密码登陆AUTOMAGIC工作预期在CakePHP中? [英] Why won't the Auth Component username & password login automagic work as expected in CakePHP?
问题描述
我试图构建登录注册页面,我的网站,与他身份验证组件,我面临的问题,
I am trying to build the login registration page for my website, I am facing problems with he Auth Component,
function beforeFilter() {
$this->Auth->loginAction = array('controller'=>'users','action'=>'login');
$this->Auth->loginRedirect = array('controller'=>'users','action'=>'landing');
$this->Auth->logoutRedirect = array('controller'=>'users','action'=>'home');
// These pages do not require authenication<br/>
$this->Auth->allow('home','register','activate','forgot','reset','_sendEmail','reset');
}
我加密和使用存储在数据库中的密码<code> $这个 - &GT; Auth-&GT;密码方法,现在甚至当我登录成功地我不重定向根据用户控制器的着陆页,我试着打印出 $这个 - &GT;验证
和它说
I am encrypting and storing the passwords in the database using $this->Auth->password
method, now even when I log in succesfully I dont get redirected to the landing page under users controller, I tried printing out $this->Auth
and it says
[loginError] => Login failed. Invalid username or password.
[authError] => You are not authorized to access that location.
另外,在我的数据库一个我现在用的验证字段是电子邮件和密码,我读的地方,该AuthComponent需要的字段是用户名和密码AUTOMAGIC工作
Also in my database the fields against which I am using authentication are email and password, I read somewhere that the AuthComponent requires the fields to be username and password for the automagic to work
我无法弄清楚什么我做错了,也登录后,如果我尝试我的浏览器指向 HTTP ://cake.localhost/users/register 它应该自动重定向我到着陆页,但它不因某种原因
I cant figure out what I am doing wrong, also after logging in, if I try to point my browser to http://cake.localhost/users/register it should automatically redirect me to the landing page but it doesnt for some reason.
任何线索,我要去的地方错了?
Any clues as to where I am going wrong?
希夫
推荐答案
从CakePHP的食谱:
From the CakePHP cookbook:
默认情况下,AuthComponent期望你有一个名为用户使用字段:用户名和密码被使用的表。
By default, the AuthComponent expects you to have a table called 'users' with fields called 'username' and 'password' to be used.
我不知道,如果你使用的AUTOMAGIC将工作电子邮件
作为字段名?
I wonder if the automagic will work if you're using email
as the field name?
尝试添加以下内容到beforefilter:
Try adding this to your beforefilter:
function beforeFilter() {
$this->Auth->fields = array(
'username' => 'email',
'password' => 'password'
);
}
这篇关于为什么不将验证组件的用户名和放大器;密码登陆AUTOMAGIC工作预期在CakePHP中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!