enable local testing without database
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,10 +94,21 @@ 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) {
|
||||||
return res.status(static.INTERNAL_SERVER_ERROR).send();
|
return done(null, false);
|
||||||
}
|
}
|
||||||
if (!rows.length) {
|
if (!rows.length) {
|
||||||
return done(null, false);
|
return done(null, false);
|
||||||
@@ -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,9 +152,10 @@ 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();
|
return res.status(status.INTERNAL_SERVER_ERROR).send();
|
||||||
return res.status(status.OK).send();
|
return res.status(status.OK).send();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user