mirror of
https://github.com/TheGreyDiamond/elevatormapRewritten.git
synced 2025-12-16 23:10:45 +01:00
Added names to submissions and made create elevator login protected
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -104,3 +104,5 @@ dist
|
|||||||
.tern-port
|
.tern-port
|
||||||
|
|
||||||
testingDONOTCOMMITME.json
|
testingDONOTCOMMITME.json
|
||||||
|
|
||||||
|
static/uploads/*
|
||||||
|
|||||||
BIN
etc/elevatormapLogo.png
Normal file
BIN
etc/elevatormapLogo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 198 KiB |
BIN
etc/elevatormapLogo.xcf
Normal file
BIN
etc/elevatormapLogo.xcf
Normal file
Binary file not shown.
96
index.js
96
index.js
@@ -189,7 +189,7 @@ function checkIfMySQLStructureIsReady() {
|
|||||||
const sql =
|
const sql =
|
||||||
"CREATE TABLE `" +
|
"CREATE TABLE `" +
|
||||||
mysqlData.database +
|
mysqlData.database +
|
||||||
"`.`elevators` ( `id` INT NOT NULL AUTO_INCREMENT , `lat` FLOAT NOT NULL , `lng` FLOAT NOT NULL , `manufacturer` VARCHAR(512) NOT NULL , `modell` VARCHAR(512) NOT NULL , `info` VARCHAR(512) NOT NULL , `visitabilty` INT NOT NULL , `technology` INT NOT NULL , `images` JSON NOT NULL , `amountOfFloors` INT NOT NULL , `maxPassangers` INT NOT NULL , `maxWeight` INT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;";
|
"`.`elevators` ( `id` INT NOT NULL AUTO_INCREMENT , `lat` FLOAT NOT NULL , `lng` FLOAT NOT NULL , `manufacturer` VARCHAR(512) NOT NULL , `modell` VARCHAR(512) NOT NULL , `info` VARCHAR(512) NOT NULL , `visitabilty` INT NOT NULL , `technology` INT NOT NULL , `images` JSON NOT NULL , `amountOfFloors` INT NOT NULL , `maxPassangers` INT NOT NULL , `maxWeight` INT NOT NULL , `creator` INT NOT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB;";
|
||||||
const newSql =
|
const newSql =
|
||||||
"CREATE TABLE `" +
|
"CREATE TABLE `" +
|
||||||
mysqlData.database +
|
mysqlData.database +
|
||||||
@@ -291,10 +291,22 @@ app.post("/login", function (req, res) {
|
|||||||
if (response) {
|
if (response) {
|
||||||
// Login okay
|
// Login okay
|
||||||
sess.username = result[0].username;
|
sess.username = result[0].username;
|
||||||
sess.id = result[0].id;
|
sess.uid = String(result[0].id);
|
||||||
sess.mail = result[0].email;
|
sess.mail = result[0].email;
|
||||||
|
|
||||||
const data = fs.readFileSync("templates/redirect.html", "utf8");
|
const data = fs.readFileSync("templates/redirect.html", "utf8");
|
||||||
|
if(req.query.r != undefined && req.query.r != ""){
|
||||||
|
res.send(
|
||||||
|
Eta.render(data, {
|
||||||
|
author: author,
|
||||||
|
desc: desc,
|
||||||
|
siteTitel: sitePrefix + "Ok",
|
||||||
|
fontawesomeKey: fontawesomeKey,
|
||||||
|
url: req.query.r,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
}else{
|
||||||
res.send(
|
res.send(
|
||||||
Eta.render(data, {
|
Eta.render(data, {
|
||||||
author: author,
|
author: author,
|
||||||
@@ -304,6 +316,8 @@ app.post("/login", function (req, res) {
|
|||||||
url: "/profile",
|
url: "/profile",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Password falsch
|
// Password falsch
|
||||||
const data = fs.readFileSync("templates/login.html", "utf8");
|
const data = fs.readFileSync("templates/login.html", "utf8");
|
||||||
@@ -772,6 +786,8 @@ app.get("/map", function (req, res) {
|
|||||||
|
|
||||||
app.get("/createElevator", function (req, res) {
|
app.get("/createElevator", function (req, res) {
|
||||||
if (mysqlIsUpAndOkay) {
|
if (mysqlIsUpAndOkay) {
|
||||||
|
|
||||||
|
if (req.session.username != undefined) {
|
||||||
const data = fs.readFileSync("templates/createElevator.html", "utf8");
|
const data = fs.readFileSync("templates/createElevator.html", "utf8");
|
||||||
res.send(
|
res.send(
|
||||||
Eta.render(data, {
|
Eta.render(data, {
|
||||||
@@ -782,6 +798,21 @@ app.get("/createElevator", function (req, res) {
|
|||||||
mapboxAccessToken: mapboxAccessToken,
|
mapboxAccessToken: mapboxAccessToken,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
const data = fs.readFileSync("templates/redirect.html", "utf8");
|
||||||
|
res.send(
|
||||||
|
Eta.render(data, {
|
||||||
|
author: author,
|
||||||
|
desc: desc,
|
||||||
|
siteTitel: sitePrefix + "Profile",
|
||||||
|
fontawesomeKey: fontawesomeKey,
|
||||||
|
url: "/login?r=/createElevator",
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const data = fs.readFileSync("templates/dbError.html", "utf8");
|
const data = fs.readFileSync("templates/dbError.html", "utf8");
|
||||||
var displayText =
|
var displayText =
|
||||||
@@ -939,11 +970,12 @@ const getAppCookies = (req) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
app.post("/api/saveNewElevatorMeta", function (req, res) {
|
app.post("/api/saveNewElevatorMeta", function (req, res) {
|
||||||
|
var sess = req.session;
|
||||||
console.log(req.headers.cookie);
|
console.log(req.headers.cookie);
|
||||||
tempJs = JSON.parse(decodeURIComponent(getAppCookies(req, res)["tempStore"]));
|
tempJs = JSON.parse(decodeURIComponent(getAppCookies(req, res)["tempStore"]));
|
||||||
console.log(tempJs);
|
console.log(tempJs);
|
||||||
const sql =
|
const sql =
|
||||||
"INSERT INTO elevators (lat, lng, manufacturer, modell, info, visitabilty, technology, amountOfFloors, maxPassangers, maxWeight, images) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '{ \"images\": []}')";
|
"INSERT INTO elevators (lat, lng, manufacturer, modell, info, visitabilty, technology, amountOfFloors, maxPassangers, maxWeight, images, creator) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '{ \"images\": []}', ?)";
|
||||||
con.query(
|
con.query(
|
||||||
sql,
|
sql,
|
||||||
[
|
[
|
||||||
@@ -957,6 +989,7 @@ app.post("/api/saveNewElevatorMeta", function (req, res) {
|
|||||||
tempJs.flor,
|
tempJs.flor,
|
||||||
tempJs.pepl,
|
tempJs.pepl,
|
||||||
tempJs.weig,
|
tempJs.weig,
|
||||||
|
sess.uid
|
||||||
],
|
],
|
||||||
function (err, result) {
|
function (err, result) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -1027,6 +1060,63 @@ app.get("/api/getElevatorLocation", function (req, res) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get("/api/resolveNameById", function (req, res) {
|
||||||
|
if (mysqlIsUpAndOkay) {
|
||||||
|
if(req.query.id != undefined && req.query.id != ""){
|
||||||
|
|
||||||
|
const sql = "SELECT username FROM users WHERE id=?";
|
||||||
|
con.query(sql, [req.query.id], function (err, result, fields) {
|
||||||
|
if (err) {
|
||||||
|
res.status(500);
|
||||||
|
res.send(
|
||||||
|
JSON.stringify({
|
||||||
|
state: "Failed",
|
||||||
|
message: "A server side error occured.",
|
||||||
|
results: [],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
logger.error("The server failed to execute a request");
|
||||||
|
mysqlIsUpAndOkay = false;
|
||||||
|
} else {
|
||||||
|
console.log(result[0]);
|
||||||
|
res.status(200);
|
||||||
|
res.setHeader("Content-Type", "application/json");
|
||||||
|
res.send(
|
||||||
|
JSON.stringify({ state: "Ok", message: "", results: result })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
res.status(400);
|
||||||
|
res.setHeader("Content-Type", "application/json");
|
||||||
|
res.send(JSON.stringify({ state: "Failed", message: "Missing argument: id" }));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const data = fs.readFileSync("templates/dbError.html", "utf8");
|
||||||
|
var displayText =
|
||||||
|
"This might be an artifact of a recent restart. Maybe wait a few minutes and reload this page.";
|
||||||
|
if (startUpTime + 60 <= Math.floor(new Date().getTime() / 1000)) {
|
||||||
|
displayText =
|
||||||
|
"The server failed to connect to the MySQL server. This means it was unable to load any data.";
|
||||||
|
}
|
||||||
|
if (mySQLstate == 1) {
|
||||||
|
displayText =
|
||||||
|
"There is a problem with the database servers setup. Please check the log for more info.";
|
||||||
|
}
|
||||||
|
|
||||||
|
res.send(
|
||||||
|
Eta.render(data, {
|
||||||
|
author: author,
|
||||||
|
desc: desc,
|
||||||
|
siteTitel: sitePrefix + "Error",
|
||||||
|
fontawesomeKey: fontawesomeKey,
|
||||||
|
displayText: displayText,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.get("/api/getElevatorById", function (req, res) {
|
app.get("/api/getElevatorById", function (req, res) {
|
||||||
console.log(req.query);
|
console.log(req.query);
|
||||||
if (req.query.id != undefined) {
|
if (req.query.id != undefined) {
|
||||||
|
|||||||
@@ -12,5 +12,7 @@
|
|||||||
|
|
||||||
<b>Type:</b> #TYPE <br>
|
<b>Type:</b> #TYPE <br>
|
||||||
<b>Max. Passerngers:</b> #MAXPASS / #MASSWEIGH (kg) <br>
|
<b>Max. Passerngers:</b> #MAXPASS / #MASSWEIGH (kg) <br>
|
||||||
<b>Visitable:</b> #VISIT
|
<b>Visitable:</b> #VISIT <br>
|
||||||
|
|
||||||
|
<i>Created by: #CREATOR</i>
|
||||||
</center>
|
</center>
|
||||||
@@ -160,6 +160,8 @@
|
|||||||
</aside>
|
</aside>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var lockMap = false;
|
||||||
|
|
||||||
function noRestore() {
|
function noRestore() {
|
||||||
off();
|
off();
|
||||||
Cookies.remove("tempStore")
|
Cookies.remove("tempStore")
|
||||||
@@ -248,6 +250,7 @@
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
console.log("DONE!")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -276,6 +279,7 @@
|
|||||||
document.getElementById("step2").style.display = 'none';
|
document.getElementById("step2").style.display = 'none';
|
||||||
document.getElementById("step3").style.display = 'block';
|
document.getElementById("step3").style.display = 'block';
|
||||||
document.getElementById("step4").style.display = 'none';
|
document.getElementById("step4").style.display = 'none';
|
||||||
|
lockMap = false;
|
||||||
}
|
}
|
||||||
if (currentPage == 3) {
|
if (currentPage == 3) {
|
||||||
document.getElementById("step1").style.display = 'none';
|
document.getElementById("step1").style.display = 'none';
|
||||||
@@ -284,6 +288,7 @@
|
|||||||
document.getElementById("step4").style.display = 'block';
|
document.getElementById("step4").style.display = 'block';
|
||||||
document.getElementById("step5").style.display = 'none';
|
document.getElementById("step5").style.display = 'none';
|
||||||
document.getElementById("missingAlert").style.display = 'none';
|
document.getElementById("missingAlert").style.display = 'none';
|
||||||
|
lockMap = true;
|
||||||
}
|
}
|
||||||
if (currentPage == 4) {
|
if (currentPage == 4) {
|
||||||
document.getElementById("step1").style.display = 'none';
|
document.getElementById("step1").style.display = 'none';
|
||||||
@@ -346,6 +351,7 @@
|
|||||||
var lngElm = document.getElementById("lng");
|
var lngElm = document.getElementById("lng");
|
||||||
|
|
||||||
latElm.addEventListener('input', function (evt) {
|
latElm.addEventListener('input', function (evt) {
|
||||||
|
if(!lockMap){
|
||||||
markers.clearLayers();
|
markers.clearLayers();
|
||||||
console.log(evt.target.value)
|
console.log(evt.target.value)
|
||||||
const lat = evt.target.value;
|
const lat = evt.target.value;
|
||||||
@@ -354,9 +360,12 @@
|
|||||||
//marker.addTo(mymap)
|
//marker.addTo(mymap)
|
||||||
markers.addLayer(marker);
|
markers.addLayer(marker);
|
||||||
markers.addTo(mymap);
|
markers.addTo(mymap);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
lngElm.addEventListener('input', function (evt) {
|
lngElm.addEventListener('input', function (evt) {
|
||||||
|
if(!lockMap){
|
||||||
markers.clearLayers();
|
markers.clearLayers();
|
||||||
console.log(evt.target.value)
|
console.log(evt.target.value)
|
||||||
const lat = latElm.value;
|
const lat = latElm.value;
|
||||||
@@ -365,6 +374,7 @@
|
|||||||
//marker.addTo(mymap)
|
//marker.addTo(mymap)
|
||||||
markers.addLayer(marker);
|
markers.addLayer(marker);
|
||||||
markers.addTo(mymap);
|
markers.addTo(mymap);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var amountOfImages = 0;
|
var amountOfImages = 0;
|
||||||
@@ -405,6 +415,7 @@
|
|||||||
home()
|
home()
|
||||||
|
|
||||||
mymap.on('click', function (e) {
|
mymap.on('click', function (e) {
|
||||||
|
if(!lockMap){
|
||||||
markers.clearLayers();
|
markers.clearLayers();
|
||||||
var coord = e.latlng;
|
var coord = e.latlng;
|
||||||
var lat = coord.lat;
|
var lat = coord.lat;
|
||||||
@@ -416,6 +427,9 @@
|
|||||||
document.getElementById("lat").value = lat
|
document.getElementById("lat").value = lat
|
||||||
document.getElementById("lng").value = lng
|
document.getElementById("lng").value = lng
|
||||||
console.log("You clicked the map at latitude: " + lat + " and longitude: " + lng);
|
console.log("You clicked the map at latitude: " + lat + " and longitude: " + lng);
|
||||||
|
}else{
|
||||||
|
console.log("The map is locked.")
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function addPin(item, index) {
|
function addPin(item, index) {
|
||||||
|
|||||||
@@ -148,6 +148,13 @@
|
|||||||
"#VISIT",
|
"#VISIT",
|
||||||
visitStates[res.results[0].visitabilty]
|
visitStates[res.results[0].visitabilty]
|
||||||
);
|
);
|
||||||
|
try{
|
||||||
|
var username = JSON.parse(httpGet("/api/resolveNameById?id=" + res.results[0].creator)).results[0].username
|
||||||
|
}catch{
|
||||||
|
username = "Unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
inspector = inspector.replace("#CREATOR", username);
|
||||||
document.getElementById("inspector").innerHTML = inspector;
|
document.getElementById("inspector").innerHTML = inspector;
|
||||||
|
|
||||||
// Make gallery
|
// Make gallery
|
||||||
|
|||||||
Reference in New Issue
Block a user