2021-11-18 05:59:27 +01:00
|
|
|
const express = require("express");
|
|
|
|
const router = express.Router();
|
2021-11-15 09:23:48 +01:00
|
|
|
|
2021-11-16 07:19:35 +01:00
|
|
|
let controller = require("../controllers/controllers");
|
2021-11-16 00:44:33 +01:00
|
|
|
|
2021-11-18 05:59:27 +01:00
|
|
|
router.get("/", (_req, res) => {
|
|
|
|
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) => {
|
2021-11-17 09:52:36 +01:00
|
|
|
if (data == 200) {
|
2021-11-18 05:59:27 +01:00
|
|
|
res.render("pages/register-verification-sent");
|
2021-11-17 09:52:36 +01:00
|
|
|
} else {
|
2021-11-18 05:59:27 +01:00
|
|
|
res.render("pages/register-error");
|
2021-11-17 09:52:36 +01:00
|
|
|
}
|
2021-11-18 05:59:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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",
|
2021-11-18 07:29:27 +01:00
|
|
|
error: "Please confim your account by checking your email",
|
2021-11-18 05:59:27 +01:00
|
|
|
});
|
|
|
|
} else if (data[0] == 205) {
|
|
|
|
res.render("pages/login", {
|
|
|
|
companyName: "SALAH",
|
2021-11-18 07:29:27 +01:00
|
|
|
error: "The Email you provided is not registered in our website",
|
2021-11-18 05:59:27 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.render("pages/login", {
|
|
|
|
companyName: "SALAH",
|
2021-11-18 07:29:27 +01:00
|
|
|
error: "Wrong Email or Password",
|
2021-11-18 05:59:27 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get("/forgot-password", (_req, res) => {
|
|
|
|
res.render("pages/forgot-password");
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get("/otp", (_req, res) => {
|
|
|
|
res.render("pages/otp");
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get("/change-password", (_req, res) => {
|
|
|
|
res.render("pages/change-password");
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get("/products", (_req, res) => {
|
|
|
|
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 });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get("/successadd", (_req, res) => {
|
|
|
|
res.render("pages/success-add");
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get("/bag", (_req, res) => {
|
|
|
|
res.render("pages/bag");
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get("/checkout", (_req, res) => {
|
|
|
|
res.render("pages/checkout");
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get("/notifpay", (_req, res) => {
|
|
|
|
res.render("pages/notif-pay");
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get("/payment", (_req, res) => {
|
|
|
|
res.render("pages/payment");
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get("/about-us", (_req, res) => {
|
|
|
|
res.render("pages/about-us");
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|