limit logout function to logged in users
This commit is contained in:
@@ -165,26 +165,21 @@ app.post("/API/user/login", passport.authenticate('local-login'), function (req,
|
|||||||
return res.status(status.OK).send("login success");
|
return res.status(status.OK).send("login success");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.delete("/API/user/logout", function (req, res) {
|
app.put("/API/user/create", function (req, res) {
|
||||||
req.logout();
|
let { email, password } = req.body;
|
||||||
return res.status(status.OK).send("logout success");
|
if (email && password) {
|
||||||
}); !!
|
email = mysql.escape(email);
|
||||||
|
password = mysql.escape(bcrypt.hashSync(password, saltRounds));
|
||||||
app.put("/API/user/create", function (req, res) {
|
if (DEBUG) return res.status(status.OK).send();
|
||||||
let { email, password } = req.body;
|
connection.query(`INSERT INTO user (deactivated, email, password) values (1, ${email}, ${password})`, function (err, rows) {
|
||||||
if (email && password) {
|
if (err)
|
||||||
email = mysql.escape(email);
|
return res.status(status.INTERNAL_SERVER_ERROR).send("the user seems to exist already - if you think this is an error contact the sys admin");
|
||||||
password = mysql.escape(bcrypt.hashSync(password, saltRounds));
|
return res.status(status.OK).send("account successfully created");
|
||||||
if (DEBUG) return res.status(status.OK).send();
|
});
|
||||||
connection.query(`INSERT INTO user (deactivated, email, password) values (1, ${email}, ${password})`, function (err, rows) {
|
} else {
|
||||||
if (err)
|
return res.status(status.BAD_REQUEST).send("invalid data supplied");
|
||||||
return res.status(status.INTERNAL_SERVER_ERROR).send("the user seems to exist already - if you think this is an error contact the sys admin");
|
}
|
||||||
return res.status(status.OK).send("account successfully created");
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return res.status(status.BAD_REQUEST).send("invalid data supplied");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.all("*", function (req, res, next) {
|
app.all("*", function (req, res, next) {
|
||||||
if (req.isAuthenticated()) {
|
if (req.isAuthenticated()) {
|
||||||
@@ -199,6 +194,11 @@ app.get("/API/testlogin", function (req, res) {
|
|||||||
return res.status(status.OK).send(req.user["email"]);
|
return res.status(status.OK).send(req.user["email"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.delete("/API/user/logout", function (req, res) {
|
||||||
|
req.logout();
|
||||||
|
return res.status(status.OK).send("logout success");
|
||||||
|
});
|
||||||
|
|
||||||
app.get('/API/day', function (req, res) {
|
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)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user