diff --git a/backend/index.js b/backend/index.js index ca313a3..2314b46 100644 --- a/backend/index.js +++ b/backend/index.js @@ -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,10 +94,21 @@ 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) { - return res.status(static.INTERNAL_SERVER_ERROR).send(); + return done(null, false); } if (!rows.length) { return done(null, false); @@ -114,9 +126,21 @@ passport.serializeUser(function (user, done) { }); passport.deserializeUser(function (id, done) { - connection.query(`select * from user where id = ${id} AND deactivated = 0`, function (err, rows) { - done(err, rows[0]); - }) + 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,9 +152,10 @@ 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(); + return res.status(status.INTERNAL_SERVER_ERROR).send(); return res.status(status.OK).send(); }); } else { @@ -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();