我知道这个问题已经被问过,但我已经通过几乎每一篇文章我能找到在互联网和没事就消失了解决我的问题-.-登录CakePHP中使用电子邮件和密码2.1
我试图让我的CakePHP 2.1应用程序使用他们的电子邮件(而不是用户名)和密码登录用户。另外,考虑到我使用的控制器称为“配置文件”,而不是“用户”。这有什么区别吗?总之,这里是我的代码...
AppController.php
<?php
class AppController extends Controller {
public $components = array(
'Session',
'Auth'=>array(
'authorize => array('Controller'),
'Form'=>array(
'fields' => array('username' => 'email'),
'userModel' => 'Profile'
)
)
);
}
?>
ProfilesController.php
<?php
class ProfilesController extends AppController {
function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->Session->setFlash('You have been signed in.', 'flash_success');
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Login failed. Your username/password was incorect.');
}
}
}
}
?>
login.ctp
<?php
echo $this->Form->create();
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->submit('Sign In');
?>
任何意见/建议,为什么这仍然登录不工作!?我很困惑。
谢谢!
嘿那里:),谢谢你回到我身边!我已经在我的AppController.php中,我也只是把它放在我的ProfilesController.php以及...仍然没有区别。它不断返回我的“登录失败”的消息!任何其他想法? –
“登录失败”?这可能是密码问题... 检查您的表单发送的密码字符串以及数据库中的值。他们是否是实例? – Matthieu
是的,密码都很好。我使用我的注册表单创建了3个额外的用户帐户,并且他们都正确地进行了散列处理。仍然没有登录。 –