diff --git a/public/js/more-info.js b/public/js/more-info.js index 80481ba..34c86f9 100644 --- a/public/js/more-info.js +++ b/public/js/more-info.js @@ -131,7 +131,7 @@ function moreInfo() { let chartData = {}; // const labels = data.map(item => new Date(item.dt.replaceAll(/[T-Z]/g, ' ').trim())); const values = data.map(item => {return {x: item.dt, y: item.val}}); - console.debug(values); + console.debug("poseidon values: ", values); chartData = { datasets: [{ label: 'Pressure', diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index 9ab604b..59b5e14 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -52,8 +52,6 @@ class AuthController { public function guestSignin() { - // header('Location: /'); - // Prevent invalid email input $email = $_POST['username']; if (!valid_email($email)) { @@ -71,6 +69,12 @@ class AuthController { header('HTTP/1.1 400 Bad Request'); exit(400); } + + if (!self::isEmail($email)) { + header('HTTP/1.1 422 Unprocessable Entity'); + header('Location: login'); + exit(422); + } // Handle guest login if (isset($_POST['username'])) { @@ -99,16 +103,19 @@ class AuthController { exit(); } + private function isEmail($email) { + return filter_var($email, FILTER_VALIDATE_EMAIL); + } + private function insertGuestUser($email) { - $uid = guidv4($email); - $sql = "INSERT INTO webapp.users (email, password, origin, geo_id) - VALUES ('${email}', '', 'GUEST', '${uid}') + $sql = "INSERT INTO webapp.users (email, origin, password) + VALUES ('${email}', 'GUEST', '') ON CONFLICT (email) DO UPDATE - SET geo_id = EXCLUDED.geo_id, - last_login = now()"; + SET last_login = now()"; - return json_decode(PgSql::insert($sql, 'geo_id'))->geo_id; + $res = PgSql::insert($sql, 'geo_id'); + return json_decode($res)->geo_id; } private function insertGuestGroup($id) {