application/core/MY_Controller.php
/***** This method is to check, User is Authenticate and Authorization or not for every request *****/
This method is to check, User is Authenticate and Authorization or not for every request
This method is to check User is Authenticate and Authorization or not for every request
public function auth()
    {
        $this->load->model('Auth_model');
        $headers = $this->input->get_request_header('Authorization');
        $key = $this->config->item('thekey'); 
        try {           
           $decoded = JWT::decode($headers, $key, array('HS256'));
           $where_query = array('EmailAddress' => $decoded->EmailAddress, 'UserId' => $decoded->UserId); 
           $val = $this->Auth_model->get_user($where_query)->row(); 
           if($this->Auth_model->get_user($where_query)->num_rows() == 0){$this->response($invalidLogin, REST_Controller::HTTP_NOT_FOUND);}
           $this->user_data = $decoded;
        } catch (Exception $e) {
            $invalid = ['status' => $e->getMessage()]; 
            $this->response($invalid, 401);
        }
    }
public function auth ( ) { $ this -> load -> model ( 'Auth_model' ) ; $ headers = $ this -> input -> get_request_header ( 'Authorization' ) ; $ key = $ this -> config -> item ( 'thekey' ) ; try { $ decoded = JWT :: decode ( $ headers , $ key , array ( 'HS256' ) ) ; $ where_query = array ( 'EmailAddress' => $ decoded -> EmailAddress , 'UserId' => $ decoded -> UserId ) ; $ val = $ this -> Auth_model -> get_user ( $ where_query ) -> row ( ) ; if ( $ this -> Auth_model -> get_user ( $ where_query ) -> num_rows ( ) == 0 ) { $ this -> response ( $ invalidLogin , REST_Controller :: HTTP_NOT_FOUND ) ; } $ this -> user_data = $ decoded ; } catch ( Exception $ e ) { $ invalid = [ 'status' => $ e -> getMessage ( ) ] ; $ this -> response ( $ invalid , 401 ) ; } }
This method is to check, User is Authenticate and Authorization or not for every request
This method is to check User is Authenticate and Authorization or not for every request
//secret key for encode and decode //For where query condition //Model to get single data row from database base on username //Respon if credential invalid //401