我使用 email_address 作为用户名进行简单登录。
public $components = array(
'DebugKit.Toolbar',
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'pages', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home'),
'loginAction' => array(
'controller' => 'users',
'action' => 'signin',
),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email_address')
)
)
),
);
我已经明确告诉 cake 使用 email_address 作为用户名
public function signin(){
if(! $this->Auth->user()){
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash(__('Username or password is incorrect'));
}
}
}else{
$this->redirect($this->Auth->redirectUrl());
}
}
我已验证我的帖子数据是通过表单发送的
<form action="" method="post" class="form-inputs">
<fieldset>
<legend>Existing Customers</legend>
<p>Sign in to continue</p>
<ul class="form short">
<li>
<label for="username">Email</label>
<input type="email" name="username" id="username">
</li>
<li>
<label for="password">Password</label>
<input type="password" name="password" id="password">
</li>
<li class="no-label checkbox">
<input type="checkbox" name="remember_me" id="remember_me">
<label for="remember_me">Remember me</label>
</li>
<li class="no-label">
<input type="submit" value="Sign In">
<a href="/">Forgotten your password?</a>
</li>
</ul>
</fieldset>
</form>
我无法成功登录。用户确实存在,并且密码在创建时被散列,如下所示:
public function beforeSave($options = array()) {
if (isset($this->data['User']['password'])) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
}
return true;
}
看不到我哪里出错了,有什么想法吗?