Merge branch 'master' into login-feedback
This commit is contained in:
@@ -36,6 +36,7 @@ const saltRounds = 13;
|
|||||||
|
|
||||||
var serverStartupComplete = false;
|
var serverStartupComplete = false;
|
||||||
|
|
||||||
|
const DEBUG = process.env.NODE_ENV === "debug" ? true : false;
|
||||||
|
|
||||||
function twoDigits(d) {
|
function twoDigits(d) {
|
||||||
if (0 <= d && d < 10) return "0" + d.toString();
|
if (0 <= d && d < 10) return "0" + d.toString();
|
||||||
@@ -62,7 +63,7 @@ app.use(session({
|
|||||||
secret: "simCoRoxUFocker",
|
secret: "simCoRoxUFocker",
|
||||||
saveUninitialized: true,
|
saveUninitialized: true,
|
||||||
resave: true,
|
resave: true,
|
||||||
store: sessionStore,
|
store: DEBUG ? undefined : sessionStore,
|
||||||
"cookie": {
|
"cookie": {
|
||||||
"maxAge": 86400 * 1000
|
"maxAge": 86400 * 1000
|
||||||
}
|
}
|
||||||
@@ -93,6 +94,17 @@ passport.use('local-login', new LocalStrategy({
|
|||||||
passwordField: "password",
|
passwordField: "password",
|
||||||
passReqToCallback: true
|
passReqToCallback: true
|
||||||
}, function (req, email, password, done) {
|
}, 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);
|
email = mysql.escape(email);
|
||||||
connection.query(`SELECT * from user WHERE email = ${email} AND deactivated = 0`, function (err, rows) {
|
connection.query(`SELECT * from user WHERE email = ${email} AND deactivated = 0`, function (err, rows) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -114,9 +126,21 @@ passport.serializeUser(function (user, done) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
passport.deserializeUser(function (id, done) {
|
passport.deserializeUser(function (id, done) {
|
||||||
connection.query(`select * from user where id = ${id} AND deactivated = 0`, function (err, rows) {
|
if (!DEBUG)
|
||||||
done(err, rows[0]);
|
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) {
|
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) {
|
if (email && password) {
|
||||||
email = mysql.escape(email);
|
email = mysql.escape(email);
|
||||||
password = mysql.escape(bcrypt.hashSync(password, saltRounds));
|
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) {
|
connection.query(`INSERT INTO user (deactivated, email, password) values (1, ${email}, ${password})`, function (err, rows) {
|
||||||
if (err)
|
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");
|
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);
|
const kind = parseInt(req.query.kind);
|
||||||
if (Number.isInteger(kind)) {
|
if (Number.isInteger(kind)) {
|
||||||
//Mock Data:
|
//Mock Data:
|
||||||
if (kind === -1) return res.send(mockDataDay);
|
if (kind === -1 || DEBUG) return res.send(mockDataDay);
|
||||||
|
|
||||||
if (kind >= 1 && kind <= 113) {
|
if (kind >= 1 && kind <= 113) {
|
||||||
var dayend = new Date().toMysqlFormat();
|
var dayend = new Date().toMysqlFormat();
|
||||||
@@ -182,4 +207,4 @@ app.get('/API/resourcelist', function (req, res) {
|
|||||||
res.send(resourceList);
|
res.send(resourceList);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(3001);
|
app.listen(3001);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
52
backend/package-lock.json
generated
52
backend/package-lock.json
generated
@@ -280,6 +280,58 @@
|
|||||||
"capture-stack-trace": "^1.0.0"
|
"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": {
|
"cross-spawn": {
|
||||||
"version": "5.1.0",
|
"version": "5.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"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"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"author": "Oliver Boehlk",
|
"author": "Oliver Boehlk",
|
||||||
@@ -23,5 +23,8 @@
|
|||||||
"nodemon": "^2.0.2",
|
"nodemon": "^2.0.2",
|
||||||
"passport": "^0.4.1",
|
"passport": "^0.4.1",
|
||||||
"passport-local": "^1.0.0"
|
"passport-local": "^1.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"cross-env": "^7.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user