-1

在下面的代码中,我在我的数据库中使用了 codeigniter,我有一个列名 account_status,默认情况下它将处于非活动状态。现在我想检查 account_status 如果它处于活动状态,它应该让我登录,否则不要。请帮我做。

控制器:

function index()
    {
        $data['main_content'] = 'login_form';
        $this->load->view('includes/template', $data);      
    }

    function validate_credentials()
    {       
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();

        if($query) // if the user's credentials validated...
        {
            $data = array(
                'username' => $this->input->post('username'),
                'is_logged_in' => true
            );
            $this->session->set_userdata($data);
            redirect('site1/members_area');
        }
        else // incorrect username or password
        {
            $this->index();
        }
    }   

站点1

function members_area()
    {
        $this->load->view('homepage_view');


    }

模型:

function validate()
    {
        $this->db->where('username', $this->input->post('username'));
        $this->db->where('password', md5($this->input->post('password')));
        $query = $this->db->get('membership');

        if($query->num_rows == 1)
        {
            return true;
        }

    }
4

1 回答 1

1

你有这些方法试试这个

只需在模型中使用 anther where 条件

function validate()
    {
        $this->db->where('username', $this->input->post('username'));
        $this->db->where('password', md5($this->input->post('password')));
        $this->db->where('account_status','active');
        $query = $this->db->get('membership');

        if($query->num_rows == 1)
        {
            return true;
        }

}

或检查控制器中的状态

function validate_credentials()
    {       
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();

        if($query) // if the user's credentials validated...
        {
            $data = array(
                'username' => $this->input->post('username'),
                'is_logged_in' => true
            );
            if($query->num_rows()>0)
             $status = $query->row()->account_status;
            else 
             $status = '';
            if($status == 'active')
            {
               $this->session->set_userdata($data);
               redirect('site1/members_area');
            }
            else //Account In active
            {  $this->index();  }
        }
        else // incorrect username or password
        {
            $this->index();
        }
    }   
于 2013-11-14T05:10:24.440 回答