登录状态检查不起作用


Login status check not working codeigniter

当任何用户尝试登录时,我正在尝试检查状态,如果状态为0,则重定向回管理员。然后,如果状态为1,则重定向到仪表板。

我已经测试过了,尽管状态为0 ,但它仍然让我把我发送到仪表板

无功转储数组(1){["status"]=>字符串(1)"0"}*

确保它检查我的登录状态的最佳解决方案是什么。

模型函数

public function getStatus() {
    $this->db->select('status');
    $this->db->from($this->db->dbprefix . 'user');
    $this->db->where('username', $this->input->post('username'));
    $query = $this->db->get();
    return $query->row_array();
}

控制器

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends Admin_Controller {

    public function index() {
        $this->form_validation->set_rules('username', 'Username', 'required|callback_validate');
        $this->form_validation->set_rules('password', 'Password', 'required');
        if ($this->form_validation->run($this) == FALSE) {
            $this->load->view('template/common/login.tpl', $this->data);
        } else {
            $this->load->model('admin/user/model_user');
            var_dump($this->model_user->getStatus());
            // array(1) { ["status"]=> string(1) "0" } 
            exit;
            if ($this->model_user->getStatus()) {
                redirect('admin/dashboard');
            } else {
                $this->session->set_flashdata('error', 'You have not been enabled by the webmaster. Please wait up to 24/48 hours. If you need to contact the website master email' .' '. config_item('config_email'));
                redirect('admin');
            }
        }
        }
    }
    public function validate() {
        $this->load->library('user');
        if ($this->user->login() == FALSE) {
            $this->form_validation->set_message('validate', '<i class="fa fa-exclamation-triangle"></i> Does not match any of our database records!');
            return false;
        } else {
            return true;
        }
    }
}

问题解决了,我不得不从控制器和模型中删除一些东西。

型号

public function getStatus() {
    $this->db->where('username', $this->input->post('username'));
    $query = $this->db->get($this->db->dbprefix . 'user');
    $ret = $query->row();
    return $ret->status;
}

控制器

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends Admin_Controller {
private $error = array();
public function __construct() {
    parent::__construct();
}
public function index() {   
    $data['title'] = 'Administration';
    $this->form_validation->set_rules('username', 'Username', 'required|callback_validate');
    $this->form_validation->set_rules('password', 'Password', 'required');
    if ($this->form_validation->run($this) == FALSE) {
        $this->load->view('template/common/login.tpl', $data);
    } else {
        $this->load->model('admin/user/model_user');
        if ($this->model_user->getStatus() == 1) {
            redirect('admin/dashboard');
        } else {
            $this->session->set_flashdata('error', 'You have not been enabled by the webmaster. Please wait up to 24/48 hours. If you need to contact the website master email' .' '. config_item('config_email'));
            redirect('admin');
        }
    }
}
public function validate() {
    $this->load->library('user');
    if ($this->user->login() == FALSE) {
        $this->form_validation->set_message('validate', '<i class="fa fa-exclamation-triangle"></i> Does not match any of our database records!');
        return false;
    } else {
        return true;
    }
}
}