From 3a82baec9d793edf81ac2b151b0f4d4159641375 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Mon, 1 Apr 2024 11:09:25 -0400 Subject: login and register, liking on homepage --- src/web/_model/main.php | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/web/_model/main.php (limited to 'src/web/_model/main.php') diff --git a/src/web/_model/main.php b/src/web/_model/main.php new file mode 100644 index 0000000..6d8b708 --- /dev/null +++ b/src/web/_model/main.php @@ -0,0 +1,96 @@ +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 + ); + } + } + + /** + * Gets the stamp for a asset path + * @param string $path + */ + private function asset_stamp($path): int { + $root = $GLOBALS['webroot']; + $path = $root . '/../public/' . $path; + return filemtime($path); + } + + /** + * Loads a css html link + * @param string $path - the path to the css file + */ + public function link_css($path) { + $stamp = $this->asset_stamp($path); + return ''; + } + + /** + * Loads a js html link + * @param string $path - the path to the js file + */ + public function link_js($path) { + $stamp = $this->asset_stamp($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; + } + } + +} + +?> -- cgit v1.2.3-freya