【发布时间】:2012-07-25 05:23:28
【问题描述】:
创建一个基本的登录页面 - 它可以正常工作,但后来我们更改了数据库,我们的重定向不再有效。
当我们登录站点时,在检查站点正在检查数据库的 sql 代码后,站点返回说用户名/密码不正确 - 它正在发送正确的信息,但不允许我们登录。
我们希望用户在登录网站时被重定向到 ebox(控制器)主页(视图)。
这是控制器中用于登录的代码
public function login(){
$this->set('title_for_layout', 'Individual Registration');
$this->set('stylesheet_used', 'style');
$this->set('image_used', 'eBOXLogo.jpg');
if ($this->request->is('post')){
if ($this->Auth->login()){
$username = $this->request->data['User']['username'];
if (0 === $this->User->find('count',array('conditions'=>array('activated'=>true,'username'=> $username)))){
$this->Session->setFlash('Sorry, your account is not validated yet.');
$this->redirect($this->referer());
}
else{
$this->Auth->user('id');
$this->redirect( array('controller' => 'Eboxs','action' => 'home'));
}
}
else{
$this->Session->setFlash('Username or password is incorrect');
}
}else{
$this->Session->setFlash('Welcome, please login');
}
}
这是视图的代码
<?php
echo $this->Form->create('User', array('action' => 'login'));
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Login');
?>
【问题讨论】:
-
移除硬编码条件并检查 - if ($this->request->data['User']['password'] == 'qazwsx'){ }
-
我删除了 if 语句,现在返回无效的用户名/密码