5 Commits

Author SHA1 Message Date
TheGreyDiamond
bc2a66236e Fixed an issues with account creation. How did this ever work? 2021-07-05 21:36:20 +02:00
TheGreyDiamond
7d5fdcef9b Wooops fix 2021-07-05 21:12:09 +02:00
TheGreyDiamond
b2708329c1 Added a license 2021-07-05 20:58:35 +02:00
TheGreyDiamond
51d92c139d Added buttons to create a new elevator 2021-07-05 20:45:57 +02:00
TheGreyDiamond
b05241f493 Added names to submissions and made create elevator login protected 2021-07-05 20:43:01 +02:00
14 changed files with 2917 additions and 26 deletions

3
.gitignore vendored
View File

@@ -80,7 +80,6 @@ typings/
# Nuxt.js build / generate output # Nuxt.js build / generate output
.nuxt .nuxt
dist
# Gatsby files # Gatsby files
.cache/ .cache/
@@ -104,3 +103,5 @@ dist
.tern-port .tern-port
testingDONOTCOMMITME.json testingDONOTCOMMITME.json
static/uploads/*

7
LICENSE Normal file
View File

@@ -0,0 +1,7 @@
Copyright © 2021 TheGreydiamond
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

BIN
etc/elevatormapLogo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

BIN
etc/elevatormapLogo.xcf Normal file

Binary file not shown.

120
index.js
View File

@@ -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,19 +291,33 @@ 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");
res.send( if(req.query.r != undefined && req.query.r != ""){
Eta.render(data, { res.send(
author: author, Eta.render(data, {
desc: desc, author: author,
siteTitel: sitePrefix + "Ok", desc: desc,
fontawesomeKey: fontawesomeKey, siteTitel: sitePrefix + "Ok",
url: "/profile", fontawesomeKey: fontawesomeKey,
}) url: req.query.r,
); })
);
}else{
res.send(
Eta.render(data, {
author: author,
desc: desc,
siteTitel: sitePrefix + "Ok",
fontawesomeKey: fontawesomeKey,
url: "/profile",
})
);
}
} else { } else {
// Password falsch // Password falsch
const data = fs.readFileSync("templates/login.html", "utf8"); const data = fs.readFileSync("templates/login.html", "utf8");
@@ -544,7 +558,7 @@ app.post("/register", function (req, res) {
var token = buffer.toString("hex"); var token = buffer.toString("hex");
con.query( con.query(
stmt, stmt,
[req.body.email, req.body.username, token], [req.body.email, req.body.username, hash],
(err, results1, fields) => { (err, results1, fields) => {
if (err) { if (err) {
res.send( res.send(
@@ -562,7 +576,7 @@ app.post("/register", function (req, res) {
// Create mail verification // Create mail verification
con.query( con.query(
stmt2, stmt2,
[req.body.email, results1.insertId, hash], [req.body.email, results1.insertId, token],
(err, results, fields) => { (err, results, fields) => {
if (err) { if (err) {
res.send( res.send(
@@ -772,7 +786,9 @@ app.get("/map", function (req, res) {
app.get("/createElevator", function (req, res) { app.get("/createElevator", function (req, res) {
if (mysqlIsUpAndOkay) { if (mysqlIsUpAndOkay) {
const data = fs.readFileSync("templates/createElevator.html", "utf8");
if (req.session.username != undefined) {
const data = fs.readFileSync("templates/createElevator.html", "utf8");
res.send( res.send(
Eta.render(data, { Eta.render(data, {
author: author, author: author,
@@ -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) {

View File

@@ -0,0 +1,60 @@
.marker-cluster-small {
background-color: rgba(181, 226, 140, 0.6);
}
.marker-cluster-small div {
background-color: rgba(110, 204, 57, 0.6);
}
.marker-cluster-medium {
background-color: rgba(241, 211, 87, 0.6);
}
.marker-cluster-medium div {
background-color: rgba(240, 194, 12, 0.6);
}
.marker-cluster-large {
background-color: rgba(253, 156, 115, 0.6);
}
.marker-cluster-large div {
background-color: rgba(241, 128, 23, 0.6);
}
/* IE 6-8 fallback colors */
.leaflet-oldie .marker-cluster-small {
background-color: rgb(181, 226, 140);
}
.leaflet-oldie .marker-cluster-small div {
background-color: rgb(110, 204, 57);
}
.leaflet-oldie .marker-cluster-medium {
background-color: rgb(241, 211, 87);
}
.leaflet-oldie .marker-cluster-medium div {
background-color: rgb(240, 194, 12);
}
.leaflet-oldie .marker-cluster-large {
background-color: rgb(253, 156, 115);
}
.leaflet-oldie .marker-cluster-large div {
background-color: rgb(241, 128, 23);
}
.marker-cluster {
background-clip: padding-box;
border-radius: 20px;
}
.marker-cluster div {
width: 30px;
height: 30px;
margin-left: 5px;
margin-top: 5px;
text-align: center;
border-radius: 15px;
font: 12px "Helvetica Neue", Arial, Helvetica, sans-serif;
}
.marker-cluster span {
line-height: 30px;
}

View File

@@ -0,0 +1,14 @@
.leaflet-cluster-anim .leaflet-marker-icon, .leaflet-cluster-anim .leaflet-marker-shadow {
-webkit-transition: -webkit-transform 0.3s ease-out, opacity 0.3s ease-in;
-moz-transition: -moz-transform 0.3s ease-out, opacity 0.3s ease-in;
-o-transition: -o-transform 0.3s ease-out, opacity 0.3s ease-in;
transition: transform 0.3s ease-out, opacity 0.3s ease-in;
}
.leaflet-cluster-spider-leg {
/* stroke-dashoffset (duration and function) should match with leaflet-marker-icon transform in order to track it exactly */
-webkit-transition: -webkit-stroke-dashoffset 0.3s ease-out, -webkit-stroke-opacity 0.3s ease-in;
-moz-transition: -moz-stroke-dashoffset 0.3s ease-out, -moz-stroke-opacity 0.3s ease-in;
-o-transition: -o-stroke-dashoffset 0.3s ease-out, -o-stroke-opacity 0.3s ease-in;
transition: stroke-dashoffset 0.3s ease-out, stroke-opacity 0.3s ease-in;
}

View File

@@ -0,0 +1,5 @@
We don't ship the .js files in the git master branch.
They are only present in version tags and in npm.
See how to get the JS files here: https://github.com/Leaflet/Leaflet.markercluster#using-the-plugin
Or how to build them: https://github.com/Leaflet/Leaflet.markercluster#building-testing-and-linting-scripts

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -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>

View File

@@ -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,17 +351,21 @@
var lngElm = document.getElementById("lng"); var lngElm = document.getElementById("lng");
latElm.addEventListener('input', function (evt) { latElm.addEventListener('input', function (evt) {
markers.clearLayers(); if(!lockMap){
console.log(evt.target.value) markers.clearLayers();
const lat = evt.target.value; console.log(evt.target.value)
const lng = lngElm.value; const lat = evt.target.value;
var marker = new theMarker([lat, lng]) const lng = lngElm.value;
//marker.addTo(mymap) var marker = new theMarker([lat, lng])
markers.addLayer(marker); //marker.addTo(mymap)
markers.addTo(mymap); markers.addLayer(marker);
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) {

View File

@@ -50,6 +50,7 @@
<h5> <h5>
Check it out now <br> Check it out now <br>
<a href= "/map" ><button class="button-primary">Visit the map <i class="fas fa-arrow-right"></i> </button></a> <a href= "/map" ><button class="button-primary">Visit the map <i class="fas fa-arrow-right"></i> </button></a>
<a href= "/createElevator" ><button class="button-primary">Create a new elevator <i class="fas fa-arrow-right"></i> </button></a>
</h5> </h5>
</div> </div>

View File

@@ -72,11 +72,17 @@
class="fas fa-map-marker-alt" class="fas fa-map-marker-alt"
onclick="home()" onclick="home()"
></i> ></i>
<i style="color: black; cursor: pointer" class="fas fas fa-plus" onclick="createNewElev()"></i>
</aside> </aside>
<!-- End Document <!-- End Document
--> -->
<script type="text/javascript"> <script type="text/javascript">
function createNewElev(){
window.location.href = "/createElevator";
}
var amountOfImages = 0; var amountOfImages = 0;
var markers = L.markerClusterGroup(); var markers = L.markerClusterGroup();
slideIndex = 1; slideIndex = 1;
@@ -119,7 +125,7 @@
res = JSON.parse(httpGet("/api/getElevatorById?id=" + this.options.id)); res = JSON.parse(httpGet("/api/getElevatorById?id=" + this.options.id));
if (res.state == "Ok") { if (res.state == "Ok") {
visitStates = [ visitStates = [
"Test elevator", "Test elevator",
"Public", "Public",
"On private property", "On private property",
"Public but locked", "Public but locked",
@@ -148,6 +154,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