mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-21 22:06:26 +01:00
Update checkout
This commit is contained in:
parent
2f0c7f069a
commit
ddf812c1d6
1 changed files with 120 additions and 79 deletions
199
routes/index.js
199
routes/index.js
|
@ -4,122 +4,163 @@ const router = express.Router();
|
|||
let controller = require("../controllers/controllers");
|
||||
|
||||
router.get("/", (_req, res) => {
|
||||
res.render("pages/index");
|
||||
res.render("pages/index");
|
||||
});
|
||||
|
||||
router
|
||||
.route("/register")
|
||||
.get((_req, res) => {
|
||||
res.render("pages/register");
|
||||
})
|
||||
.post((req, res) => {
|
||||
controller
|
||||
.register(
|
||||
req.body.email,
|
||||
req.body.password,
|
||||
req.body.first_name,
|
||||
req.body.last_name
|
||||
)
|
||||
.then((data) => {
|
||||
if (data == 200) {
|
||||
res.render("pages/register-verification-sent");
|
||||
} else {
|
||||
res.render("pages/register-error");
|
||||
}
|
||||
});
|
||||
});
|
||||
router.route("/register")
|
||||
.get((_req, res) => {
|
||||
res.render("pages/register");
|
||||
})
|
||||
.post((req, res) => {
|
||||
controller.register(
|
||||
req.body.email,
|
||||
req.body.password,
|
||||
req.body.first_name,
|
||||
req.body.last_name
|
||||
)
|
||||
.then((data) => {
|
||||
if (data == 200) {
|
||||
res.render("pages/register-verification-sent");
|
||||
} else {
|
||||
res.render("pages/register-error");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
router
|
||||
.route("/login")
|
||||
.get((_req, res) => {
|
||||
res.render("pages/login");
|
||||
})
|
||||
.post((req, res) => {
|
||||
controller
|
||||
.login(
|
||||
req.body.email,
|
||||
req.body.password,
|
||||
req.headers["user-agent"],
|
||||
req.headers["x-forwarded-for"] || req.socket.remoteAddress
|
||||
)
|
||||
.then((data) => {
|
||||
if (data[0] == 200) {
|
||||
res.render("pages/index");
|
||||
} else if (data[0] == 204) {
|
||||
res.render("pages/login", {
|
||||
companyName: "SALAH",
|
||||
error: "Please confim your account by checking your email",
|
||||
});
|
||||
} else if (data[0] == 205) {
|
||||
res.render("pages/login", {
|
||||
companyName: "SALAH",
|
||||
error: "Wrong Email or Password",
|
||||
});
|
||||
} else {
|
||||
res.render("pages/login", {
|
||||
companyName: "SALAH",
|
||||
error: "Wrong Email or Password",
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
router.route("/login")
|
||||
.get((_req, res) => {
|
||||
res.render("pages/login");
|
||||
})
|
||||
.post((req, res) => {
|
||||
controller.login(
|
||||
req.body.email,
|
||||
req.body.password,
|
||||
req.headers["user-agent"],
|
||||
req.headers["x-forwarded-for"] || req.socket.remoteAddress
|
||||
)
|
||||
.then((data) => {
|
||||
if (data[0] == 200) {
|
||||
res.render("pages/index");
|
||||
} else if (data[0] == 204) {
|
||||
res.render("pages/login", {
|
||||
companyName: "SALAH",
|
||||
error: "Please confim your account by checking your email",
|
||||
});
|
||||
} else if (data[0] == 205) {
|
||||
res.render("pages/login", {
|
||||
companyName: "SALAH",
|
||||
error: "Wrong Email or Password",
|
||||
});
|
||||
} else {
|
||||
res.render("pages/login", {
|
||||
companyName: "SALAH",
|
||||
error: "Wrong Email or Password",
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/verify-mail", (req, res) => {
|
||||
controller.verify_mail(req.params.token).then((data) => {
|
||||
if (data == 200) {
|
||||
res.render("pages/register-verification-success");
|
||||
} else {
|
||||
res.render("pages/index");
|
||||
}
|
||||
});
|
||||
controller.verify_mail(req.params.token).then((data) => {
|
||||
if (data == 200) {
|
||||
res.render("pages/register-verification-success");
|
||||
} else {
|
||||
res.render("pages/index");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
router.route("/checkout")
|
||||
.get((_req, res) => {
|
||||
res.render("pages/checkout");
|
||||
})
|
||||
.post((req, res) => {
|
||||
controller.checkout(
|
||||
req.body.firstName,
|
||||
req.body.lastName,
|
||||
req.body.phoneNumber,
|
||||
req.body.streetAddress1,
|
||||
req.body.streetAddress2,
|
||||
req.body.region,
|
||||
req.body.province,
|
||||
req.body.city,
|
||||
req.body.district,
|
||||
req.body.subDistrict,
|
||||
req.body.postalCode,
|
||||
req.body.logistic,
|
||||
req.body.data
|
||||
)
|
||||
.then((data) => {
|
||||
if (data[0] == 201) {
|
||||
let total_price = 0;
|
||||
let state = 0;
|
||||
let order_data = JSON.parse(data[1].data);
|
||||
for (let i=0; i<order_data.length; i++) {
|
||||
controller.getProduct(order_data[i].product_id).then((resp) => {
|
||||
state++;
|
||||
total_price += parseInt(resp[0].PRICE * order_data[i].quantity);
|
||||
if (state == order_data.length) {
|
||||
res.render("pages/payment", {
|
||||
orderId: data[1].order_id,
|
||||
totalPrice: total_price,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/forgot-password", (_req, res) => {
|
||||
res.render("pages/forgot-password");
|
||||
res.render("pages/forgot-password");
|
||||
});
|
||||
|
||||
router.get("/otp", (_req, res) => {
|
||||
res.render("pages/otp");
|
||||
res.render("pages/otp");
|
||||
});
|
||||
|
||||
router.get("/change-password", (_req, res) => {
|
||||
res.render("pages/change-password");
|
||||
res.render("pages/change-password");
|
||||
});
|
||||
|
||||
router.get("/products", (_req, res) => {
|
||||
controller.getProducts().then((data) => {
|
||||
res.render("pages/products", { data: data });
|
||||
});
|
||||
controller.getProducts().then((data) => {
|
||||
res.render("pages/products", {
|
||||
data: data
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/product/:id", (req, res) => {
|
||||
controller.getProduct(req.params.id).then((data) => {
|
||||
res.render("pages/product", { data: data });
|
||||
});
|
||||
controller.getProduct(req.params.id).then((data) => {
|
||||
res.render("pages/product", {
|
||||
data: data
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/successadd", (_req, res) => {
|
||||
res.render("pages/success-add");
|
||||
res.render("pages/success-add");
|
||||
});
|
||||
|
||||
router.get("/bag", (_req, res) => {
|
||||
res.render("pages/bag");
|
||||
res.render("pages/bag");
|
||||
});
|
||||
|
||||
router.get("/checkout", (_req, res) => {
|
||||
res.render("pages/checkout");
|
||||
res.render("pages/checkout");
|
||||
});
|
||||
|
||||
router.get("/notifpay", (_req, res) => {
|
||||
res.render("pages/notif-pay");
|
||||
res.render("pages/notif-pay");
|
||||
});
|
||||
|
||||
router.get("/payment", (_req, res) => {
|
||||
res.render("pages/payment");
|
||||
res.render("pages/login-error");
|
||||
});
|
||||
|
||||
router.get("/about-us", (_req, res) => {
|
||||
res.render("pages/about-us");
|
||||
res.render("pages/about-us");
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
module.exports = router;
|
Loading…
Reference in a new issue