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() { @@ -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',

23
src/Controllers/AuthController.php

@ -52,8 +52,6 @@ class AuthController { @@ -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 { @@ -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 { @@ -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) {

Loading…
Cancel
Save