db = new DatabaseHelper();
/// load the current session
if (array_key_exists('jwt', $_SESSION)) {
$this->get_session($_SESSION['jwt']);
} else {
$this->session = NULL;
};
/// init other vars
$this->users = array();
}
/**
* Loads current session
* @param string $jwt - the user provided JWT
*/
private function get_session($jwt) {
$query = $this->db
->select("_api.verify_jwt('" . $jwt . "') AS user_id;");
$result = $query->row();
$user_id = $result['user_id'];
if ($user_id) {
$this->session = array(
'id' => $user_id,
'jwt' => $jwt
);
}
}
/**
* Loads a css html link
* @param string $path - the path to the css file
*/
public function link_css($path) {
return '';
}
/**
* Loads a js html link
* @param string $path - the path to the js file
*/
public function link_js($path) {
return '';
}
/**
* Gets the current user
*/
public function user() {
if ($this->session) {
return $this->db
->select('*')
->from('api.user')
->where('id')
->eq($this->session['id'])
->row();
} else {
return NULL;
}
}
}
?>