This commit is contained in:
Moe Poi ~ 2021-11-21 14:05:15 +07:00
parent 62baeb4abc
commit 3465ed52c8

View file

@ -238,7 +238,7 @@ router.post("/login", async (req, res) => {
} }
}); });
router.get("/verify-mail", async (req, res) => { router.post("/verify-mail", async (req, res) => {
const conn = db.connect(); const conn = db.connect();
conn.query( conn.query(
'SELECT * FROM users WHERE token ="' + req.query.token + '"', 'SELECT * FROM users WHERE token ="' + req.query.token + '"',
@ -253,6 +253,7 @@ router.get("/verify-mail", async (req, res) => {
if (result[0].verify == 0) { if (result[0].verify == 0) {
var data = { var data = {
verify: 1, verify: 1,
token: randtoken.generate(64),
}; };
db_connect.query( db_connect.query(
'UPDATE users SET ? WHERE email ="' + result[0].email + '"', 'UPDATE users SET ? WHERE email ="' + result[0].email + '"',
@ -400,6 +401,14 @@ router.post("/reset-password", async (req, res) => {
}); });
router.post("/checkout", async (req, res) => { router.post("/checkout", async (req, res) => {
if (!req.query.key) {
res.status(401);
res.json({
message: "Unauthorized",
});
} else {
auth.auth_checker(req.query.key).then((status) => {
if (status) {
if ( if (
!req.body.firstName || !req.body.firstName ||
!req.body.lastName || !req.body.lastName ||
@ -421,6 +430,16 @@ router.post("/checkout", async (req, res) => {
}); });
} else { } else {
const conn = db.connect(); const conn = db.connect();
conn.query(
"SELECT * FROM users WHERE token = ?",
[req.query.key],
async function (error, resp, fields) {
if (error) {
res.status(401);
res.json({
message: "Unauthorized",
});
} else {
var data = { var data = {
firstName: req.body.firstName, firstName: req.body.firstName,
lastName: req.body.lastName, lastName: req.body.lastName,
@ -436,7 +455,7 @@ router.post("/checkout", async (req, res) => {
logistic: req.body.logistic, logistic: req.body.logistic,
paymentMethod: '-', paymentMethod: '-',
data: req.body.data, data: req.body.data,
userId: 14, userId: resp[0].id,
paid: '0', paid: '0',
status: 'pending' status: 'pending'
}; };
@ -470,6 +489,63 @@ router.post("/checkout", async (req, res) => {
} }
); );
} }
}
);
}
} else {
res.status(401);
res.json({
message: "Unauthorized",
});
}
});
}
}); });
router.get("/subscribe", (req, res) => {
if (!req.query.email) {
res.status(400);
res.json({
message: "Bad Request",
});
} else {
const conn = db.connect();
conn.execute(
"SELECT * FROM `subscribe` WHERE `email` = ?",
[req.query.email],
function (err, results) {
if (!results[0]) {
let data = {
email: req.query.email,
type: "email"
};
conn.query(
"INSERT INTO subscribe SET ?",
data,
function (err, resp) {
if (err) {
res.status(400);
res.json({
message: "Bad Request",
});
} else {
res.status(201);
res.json({
message: "Success",
});
}
}
);
} else {
res.status(200);
res.json({
message: "Success",
});
}
}
);
}
});
module.exports = router; module.exports = router;