How to handle value and use for certain action in CodeIgniter?

0

I am creating a system, in which the user when registering needs to be verified before the access is released.

I have the following in the database:

use_status => 1; For approved users! use_status => 2; For users under review!

I want as long as status is 2, it can not log in, but I can not do this.

user_model:

public function login($email, $password) {
    $this->db->limit(1);
    $this->db->where('use_email', $email);
    $this->db->where('use_password', $password);
    $this->db->select("use_id");
    $query = $this->db->get('users');
    $query = $query->result();

    if ($query) {
        return $query[0]->use_id;
    } else {
        return false;
    }
}

public function blockUser($status){
    $status = $this->db->select('use_status');

    if($status == 2){
        redirect('login/out');
    }
}

controller login:

public function in()
    {
        $email = $this->input->post('email');
        $password = md5($this->input->post('password'));

        $login = $this->user_model->login($email, $password);
        $blockUser = $this->user_model->blockUser($status);


        if($login){

             $this->session->set_userdata('login', $login, $blockUser);

                $data = array(
                    'use_date_login' => date('Y-m-d H:i:s'),
                    'use_last_ip' => $_SERVER['REMOTE_ADDR']
                );

                $this->user_model->update($data, $login);

                echo "login_success";

        }else{
            $this->session->set_userdata('login', false);

            echo "login_error";
        }
    }
    
asked by anonymous 08.05.2018 / 02:08

1 answer

0

Hello, I do not see the need to use two methods for this, that would be enough:

public function login($email, $password) {
    $this->db->limit(1);
    $this->db->where('use_email', $email);
    $this->db->where('use_password', $password);
    $this->db->where('use_status', 1);
    $this->db->select("use_id");
    $query = $this->db->get('users');
    $query = $query->result();

    if ($query) {
        return $query[0]->use_id;
    } else {
        return false;
    }
}

Or, if you still prefer to use blockUser , you need to redo it, why is it not doing anything at the moment, where did the $status parameter go into blockUser ? And realize that as much as you pass this parameter into the method, there you are overwriting its value, it does not make much sense to rsrs.

    
17.05.2018 / 18:33