2021-11-02 06:20:20 +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-09 03:13:22 +01:00
|
|
|
router.get('/', (_req, res) => {
|
2021-11-09 03:11:53 +01:00
|
|
|
res.render('pages/index');
|
|
|
|
})
|
|
|
|
|
2021-11-16 07:19:35 +01:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
2021-11-17 09:22:25 +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',
|
|
|
|
error : 'Please confirm your email'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.render('pages/login', {
|
|
|
|
companyName : 'SALAH',
|
2021-11-17 09:25:21 +01:00
|
|
|
error : 'Invalid Email or Password'
|
2021-11-17 09:22:25 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
2021-11-09 03:11:53 +01:00
|
|
|
|
2021-11-17 09:52:36 +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");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-11-09 03:20:03 +01:00
|
|
|
router.get('/forgot-password', (_req, res) => {
|
2021-11-09 03:11:53 +01:00
|
|
|
res.render('pages/forgot-password');
|
|
|
|
})
|
|
|
|
|
2021-11-09 03:20:03 +01:00
|
|
|
router.get('/otp', (_req, res) => {
|
2021-11-09 03:11:53 +01:00
|
|
|
res.render('pages/otp');
|
|
|
|
})
|
|
|
|
|
2021-11-16 06:35:11 +01:00
|
|
|
router.get('/change-password', (_req, res) => {
|
|
|
|
res.render('pages/change-password');
|
|
|
|
})
|
|
|
|
|
2021-11-15 10:55:33 +01:00
|
|
|
router.get('/products', (_req, res) => {
|
2021-11-16 07:19:35 +01:00
|
|
|
controller.getProducts().then(data => {
|
2021-11-16 00:44:33 +01:00
|
|
|
res.render('pages/products', {data: data});
|
|
|
|
})
|
2021-11-15 10:55:33 +01:00
|
|
|
})
|
|
|
|
|
2021-11-16 00:44:33 +01:00
|
|
|
router.get('/product/:id', (req, res) => {
|
2021-11-16 09:48:39 +01:00
|
|
|
controller.getProduct(req.params.id).then(data => {
|
2021-11-16 00:44:33 +01:00
|
|
|
res.render('pages/product', {data: data});
|
|
|
|
})
|
2021-11-02 06:20:20 +01:00
|
|
|
})
|
|
|
|
|
2021-11-09 03:13:22 +01:00
|
|
|
router.get(('/successadd'), (_req, res) => {
|
2021-11-09 03:12:36 +01:00
|
|
|
res.render('pages/success-add')
|
2021-11-02 06:20:20 +01:00
|
|
|
})
|
|
|
|
|
2021-11-09 03:13:22 +01:00
|
|
|
router.get('/bag', (_req, res) => {
|
2021-11-02 06:20:20 +01:00
|
|
|
res.render('pages/bag')
|
|
|
|
})
|
|
|
|
|
2021-11-09 03:13:22 +01:00
|
|
|
router.get('/checkout', (_req, res) => {
|
2021-11-02 06:20:20 +01:00
|
|
|
res.render('pages/checkout')
|
|
|
|
})
|
|
|
|
|
2021-11-09 03:13:22 +01:00
|
|
|
router.get('/notifpay', (_req, res) => {
|
2021-11-09 03:12:36 +01:00
|
|
|
res.render('pages/notif-pay')
|
2021-11-02 06:20:20 +01:00
|
|
|
})
|
|
|
|
|
2021-11-09 03:13:22 +01:00
|
|
|
router.get('/payment', (_req, res) => {
|
2021-11-02 06:20:20 +01:00
|
|
|
res.render('pages/payment')
|
|
|
|
})
|
|
|
|
|
2021-11-09 03:53:46 +01:00
|
|
|
router.get('/about-us', (_req, res) => {
|
|
|
|
res.render('pages/about-us')
|
|
|
|
})
|
|
|
|
|
2021-11-02 06:20:20 +01:00
|
|
|
module.exports = router;
|