[eluser]cmgmyr[/eluser]
Hey all,
I'm new at CI (and to the forum) so sorry for the noobish questions.
The view:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=$title?></title>
[removed][removed]
[removed][removed]
[removed]
function sendForm(container) {
var url = '<?=base_url()?>admin/home/login';
var params = Form.serialize(container);
var ajax = new Ajax.Request(url,{
method: 'post',
parameters: params,
onComplete: showErrors
});
}
function showErrors(req){
if(req.responseText == 'OK'){
location.href='<?=site_url("admin/catalog")?>';
}else{
$('error_messages')[removed] = req.responseText;
new Effect.Appear('error_messages');
}
}
[removed]
</head>
<body>
<div id="error_messages" style="display:none;"></div>
<form id="frm_login">
<p><input id="email" name="email" type="text" /></p>
<p><input id="password" name="password" type="text" /></p>
<p><input name="submit" type="submit" value="Login!" /></p>
</form>
</body>
</html>
The Controller:
Code:
function login(){
$email = $this->input->post('email');
$password = $this->input->post('password');
$logged_in = $this->doLogin($email, $password);
if($logged_in){
//echo 'OK';
//$this->func->pageForward(site_url("admin/catalog"));
redirect(site_url("admin/catalog"), 'refresh');
}
}
function doLogin($user_email, $user_password){
if(!$this->val->check_email($user_email)){
$this->error->setError("Email address is not valid");
}
if(!$this->val->check_input($user_password)){
$this->error->setError("Password is not valid");
}
if(!$this->error->countErrors()){
//Check the database for correct information
$sql = "SELECT * FROM admin WHERE email = '".$user_email."' LIMIT 1";
$query = $this->db->query($sql);
if($query->num_rows() == 0){
$this->error->setError("Email address not found");
}else{
//Check for both email and password
$row = $query->row();
$db_password = $row->password;
if(!$this->func->validate_password($user_password, $db_password)){
$this->error->setError("Password doesn't match database");
}else{
$id = $row->id;
//See if user account is active or not
$sql = "SELECT * FROM admin WHERE id = '$id' AND active = '0'";
$query = $this->db->query($sql);
if($query->num_rows() > 0){
$this->error->setError("Your account is disabled, this might be becuase your account is not approved yet or you have violated the TOS.");
}
if(!$this->error->countErrors()){
//Log user in
$newdata = array('admin_id' => $id);
$this->session->set_userdata($newdata);
return true;
}
}
}
}
if($this->error->countErrors()){
$this->error->showErrors();
}
return false;
}
As you can probably see in the JS the redirect in the showErrors() does work BUT I would rather do the redirect in the controller. How it is set up now it shows admin/catalog in the "error_messages" div. Any ideas how I can redirect the whole page and not just the div?
Thanks,
-Chris