How to treat value and use for certain action in Codeigniter?

Asked

Viewed 46 times

0

I am creating a system, in which the user when registering needs to be checked before the release of access.

I have in the bank the following:

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

I want as long as status is 2, he can’t log in, but I can’t 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";
        }
    }

1 answer

0


Hello, I don’t see the need to use two methods for that:

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 the blockUser, you need to redo it, because it is not doing anything at the moment, where the parameter came from $status that you pass into blockUser? And note that as much as you pass this parameter inside the method, there you are overwriting its value, it doesn’t make much sense rsrs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.