Merge branch 'master' into login-feedback

This commit is contained in:
2020-04-30 22:36:28 +02:00
4 changed files with 1146 additions and 480 deletions

View File

@@ -36,6 +36,7 @@ const saltRounds = 13;
var serverStartupComplete = false;
const DEBUG = process.env.NODE_ENV === "debug" ? true : false;
function twoDigits(d) {
if (0 <= d && d < 10) return "0" + d.toString();
@@ -62,7 +63,7 @@ app.use(session({
secret: "simCoRoxUFocker",
saveUninitialized: true,
resave: true,
store: sessionStore,
store: DEBUG ? undefined : sessionStore,
"cookie": {
"maxAge": 86400 * 1000
}
@@ -93,6 +94,17 @@ passport.use('local-login', new LocalStrategy({
passwordField: "password",
passReqToCallback: true
}, function (req, email, password, done) {
if (DEBUG) {
if (email === "test" && password === "test") {
return done(null, {
deactivated: false,
email: "test1",
id: 0,
created: new Date(),
password: "test"
});
} else return done(null, false);
}
email = mysql.escape(email);
connection.query(`SELECT * from user WHERE email = ${email} AND deactivated = 0`, function (err, rows) {
if (err) {
@@ -114,9 +126,21 @@ passport.serializeUser(function (user, done) {
});
passport.deserializeUser(function (id, done) {
if (!DEBUG)
connection.query(`select * from user where id = ${id} AND deactivated = 0`, function (err, rows) {
done(err, rows[0]);
})
else {
if (id === 0) {
done(null, {
deactivated: false,
email: "test1",
id: 0,
created: new Date(),
password: "test"
});
} else return done(null, []);
}
});
app.post("/API/user/login", passport.authenticate('local-login'), function (req, res) {
@@ -128,6 +152,7 @@ app.put("/API/user/create", function (req, res) {
if (email && password) {
email = mysql.escape(email);
password = mysql.escape(bcrypt.hashSync(password, saltRounds));
if (DEBUG) return res.status(status.OK).send();
connection.query(`INSERT INTO user (deactivated, email, password) values (1, ${email}, ${password})`, function (err, rows) {
if (err)
return res.send(status.INTERNAL_SERVER_ERROR).send("the user seems to exist already - if you think this is an error contact the sys admin");
@@ -155,7 +180,7 @@ app.get('/API/day', function (req, res) {
const kind = parseInt(req.query.kind);
if (Number.isInteger(kind)) {
//Mock Data:
if (kind === -1) return res.send(mockDataDay);
if (kind === -1 || DEBUG) return res.send(mockDataDay);
if (kind >= 1 && kind <= 113) {
var dayend = new Date().toMysqlFormat();

File diff suppressed because it is too large Load Diff

View File

@@ -280,6 +280,58 @@
"capture-stack-trace": "^1.0.0"
}
},
"cross-env": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.2.tgz",
"integrity": "sha512-KZP/bMEOJEDCkDQAyRhu3RL2ZO/SUVrxQVI0G3YEQ+OLbRA3c6zgixe8Mq8a/z7+HKlNEjo8oiLUs8iRijY2Rw==",
"dev": true,
"requires": {
"cross-spawn": "^7.0.1"
},
"dependencies": {
"cross-spawn": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.2.tgz",
"integrity": "sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==",
"dev": true,
"requires": {
"path-key": "^3.1.0",
"shebang-command": "^2.0.0",
"which": "^2.0.1"
}
},
"path-key": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
"dev": true
},
"shebang-command": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
"dev": true,
"requires": {
"shebang-regex": "^3.0.0"
}
},
"shebang-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
"dev": true
},
"which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
"dev": true,
"requires": {
"isexe": "^2.0.0"
}
}
}
},
"cross-spawn": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",

View File

@@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"start": "node index.js",
"debug": "nodemon index.js",
"debug": "cross-env NODE_ENV=debug nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Oliver Boehlk",
@@ -23,5 +23,8 @@
"nodemon": "^2.0.2",
"passport": "^0.4.1",
"passport-local": "^1.0.0"
},
"devDependencies": {
"cross-env": "^7.0.2"
}
}