I have created some code called LoginController
. Whenever Admin
gets successfully logged in I redirect the page to index
.
However, I got an error like "problem on loading page".
This is my code:
<?php
class LoginController extends AdminAppController {
var $name = 'Login';
var $uses = array('Admin.Login');
var $sessionkey= '';
/*function beforeFilter()
{
if($this->Session->read('user')=='Admin' || $this->params['action']=='login')
{
echo "in"; exit;
}
else
{
echo "else"; exit;
$this->Session->setFlash('Login first','flash_failure');
$this->redirect(array('action'=>'login'));
}
}*/
function index() {
}
function login()
{
//pr($this->data); exit;
if(!empty($this->data))
{
$results = $this->Login->findByEmail($this->data['Login']['email']);
if(!empty($results) && $results['Login']['password']== md5($this->data['Login']['password']))
{
$this->Session->write('user', 'Admin');
$results['Login']['last_login']=date("Y-m-d H:i:s");
$this->Login->save($results);
$this->Session->setFlash('Login successfully.', 'flash_success');
$this->redirect(array('controller'=>'login','action' => 'index'));
}
}
}
}
?>
Can anyone help me? Thanks.