Exemplo n.º 1
0
 public function login()
 {
     $res = new stdClass();
     $res->success = FALSE;
     $data = new stdClass();
     parse_str(file_get_contents("php://input"), $data);
     $data = (object) $data;
     $this->load->model('sp_model');
     $where = 'userName="******"';
     $arr = $this->sp_model->where('jwt_user', $where, 'id', 'asc');
     if (count($arr) == 1) {
         if (Password::validate_password($data->password, $arr[0]->password)) {
             $res->success = true;
             $token = array();
             $token['id'] = $arr[0]->id;
             $res->access_token = JWT::encode($token, $this->config->item('jwt_key'));
             $res->id = $arr[0]->id;
         } else {
             $res->error = 'Invalid user name or password.';
             http_response_code(401);
         }
     } else {
         $res->error = 'Invalid user name or password.';
         http_response_code(401);
     }
     $this->load->view('json', array('output' => $res));
 }
Exemplo n.º 2
0
 public function login($email, $password)
 {
     $this->db->select('*');
     $this->db->from('users');
     $this->db->where('email', $email);
     $this->db->limit(1);
     $query = $this->db->get();
     if ($query->num_rows() == 1) {
         $result = $query->result();
         if (Password::validate_password($password, $result[0]->password)) {
             return $result[0]->id;
         }
         return false;
     }
     return false;
 }