Browse Source

fixes in guest login and simplificaitons

master
o.moresis 9 months ago
parent
commit
0fe1c02884
  1. 2
      public/js/more-info.js
  2. 23
      src/Controllers/AuthController.php

2
public/js/more-info.js

@ -131,7 +131,7 @@ function moreInfo() {
let chartData = {}; let chartData = {};
// const labels = data.map(item => new Date(item.dt.replaceAll(/[T-Z]/g, ' ').trim())); // 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}}); const values = data.map(item => {return {x: item.dt, y: item.val}});
console.debug(values); console.debug("poseidon values: ", values);
chartData = { chartData = {
datasets: [{ datasets: [{
label: 'Pressure', label: 'Pressure',

23
src/Controllers/AuthController.php

@ -52,8 +52,6 @@ class AuthController {
public function guestSignin() { public function guestSignin() {
// header('Location: /');
// Prevent invalid email input // Prevent invalid email input
$email = $_POST['username']; $email = $_POST['username'];
if (!valid_email($email)) { if (!valid_email($email)) {
@ -71,6 +69,12 @@ class AuthController {
header('HTTP/1.1 400 Bad Request'); header('HTTP/1.1 400 Bad Request');
exit(400); exit(400);
} }
if (!self::isEmail($email)) {
header('HTTP/1.1 422 Unprocessable Entity');
header('Location: login');
exit(422);
}
// Handle guest login // Handle guest login
if (isset($_POST['username'])) { if (isset($_POST['username'])) {
@ -99,16 +103,19 @@ class AuthController {
exit(); exit();
} }
private function isEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
private function insertGuestUser($email) { private function insertGuestUser($email) {
$uid = guidv4($email); $sql = "INSERT INTO webapp.users (email, origin, password)
$sql = "INSERT INTO webapp.users (email, password, origin, geo_id) VALUES ('${email}', 'GUEST', '')
VALUES ('${email}', '', 'GUEST', '${uid}')
ON CONFLICT (email) DO UPDATE ON CONFLICT (email) DO UPDATE
SET geo_id = EXCLUDED.geo_id, SET last_login = now()";
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) { private function insertGuestGroup($id) {

Loading…
Cancel
Save