创建一个基本的登录页面 - 它正在工作,但后来我们更改了我们的数据库,我们的重定向不再工作。
当我们登录站点时,在检查站点正在检查数据库的 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');
?>