Základ zobrazování ověřených uživatelů

This commit is contained in:
2023-07-30 23:36:18 +02:00
parent 028186c8ea
commit 8a75c98c9a
6 changed files with 79 additions and 22 deletions

View File

@@ -8,7 +8,7 @@ import dotenv from 'dotenv';
import path from 'path';
import { getMenuSladovnicka, getMenuTechTower, getMenuUMotliku } from "./restaurants";
import { getQr } from "./qr";
import { generateToken, getLogin, verify } from "./auth";
import { generateToken, getLogin, getTrusted, verify } from "./auth";
import { Locations, Restaurants } from "../../types";
const ENVIRONMENT = process.env.NODE_ENV || 'production';
@@ -62,7 +62,7 @@ app.post("/api/login", (req, res) => {
// Autentizace pomocí trusted headers
const remoteUser = req.header('remote-user');
if (remoteUser && remoteUser.length > 0) {
res.status(200).json(generateToken(remoteUser));
res.status(200).json(generateToken(remoteUser, true));
return;
}
// Klasická autentizace loginem
@@ -70,7 +70,7 @@ app.post("/api/login", (req, res) => {
throw Error("Nebyl předán login");
}
// TODO zavést podmínky pro délku loginu (min i max)
res.status(200).json(generateToken(req.body.login));
res.status(200).json(generateToken(req.body.login, false));
});
// TODO dočasné řešení - QR se zobrazuje přes <img>, nemáme sem jak dostat token
@@ -207,8 +207,9 @@ app.post("/api/finishDelivery", (req, res) => {
app.post("/api/addChoice", (req, res) => {
const login = getLogin(parseToken(req));
const trusted = getTrusted(parseToken(req));
if (req.body.locationIndex > -1) {
const data = addChoice(login, req.body.locationIndex, req.body.foodIndex);
const data = addChoice(login, trusted, req.body.locationIndex, req.body.foodIndex);
io.emit("message", data);
res.status(200).json(data);
}