-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
124 lines (105 loc) · 2.97 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
express = require('express')
bodyParser = require("body-parser");
app = express();
expressLayouts = require('express-ejs-layouts');
http = require('http').Server(app);
session = require('express-session');
htmlspecialchars = require('htmlspecialchars');
crypto = require('crypto');
//Different Modules
authenticate = require('./lib/authenticate.js');
buyer = require('./lib/buyer.js');
shopit = require('./lib/shopit.js');
checkout = require('./lib/checkout.js');
app.use(session({secret: '5H0P17!'}));
app.use(express.static(__dirname + '/public'));
app.use(expressLayouts);
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.set('layout');
app.set('view engine', 'ejs');
app.set('views', __dirname + '/views');
app.set('port',(process.env.PORT||3000));
config = require('./config/config.json');
mysql = require('mysql');
connection = mysql.createConnection(config);
connection.connect();
http.listen(app.get('port'),function()
{
console.log("Listening to port number "+app.get('port'));
});
app.get('/', function(req, res)
{
var shopit_instance = new shopit();
var ses = req.session;
if(ses.logged == 1)
{
if(ses.user_type == 1)
return res.redirect('/catalogue/');
else
return res.redirect('/inventory/');
}
else
return shopit_instance.viewMain(req,res);
});
//Using Authenticate Module
app.get('/login/',function(req,res)
{
var authenticate_instance = new authenticate();
return authenticate_instance.login(req,res);
});
app.post('/login_auth/',function(req,res)
{
var authenticate_instance = new authenticate();
return authenticate_instance.loginAuth(req,res);
});
app.get('/logout/',function(req,res)
{
var authenticate_instance = new authenticate();
return authenticate_instance.logout(req,res);
});
app.post('/signup/',function(req,res)
{
var authenticate_instance = new authenticate();
return authenticate_instance.signup(req,res);
});
//Using Buyer Module
app.get('/cart/',function(req,res) //View items in the Cart
{
var buyer_instance = new buyer();
return buyer_instance.viewCart(req,res);
});
app.post('/cart/add/',function (req, res) //Add to Cart
{
var buyer_instance = new buyer();
return buyer_instance.addToCart(req,res);
});
app.post('/cart/delete/',function (req, res) //Delete from Cart
{
var buyer_instance = new buyer();
return buyer_instance.deleteFromCart(req,res);
});
//Using ShopIt Module
app.get('/catalogue/', function (req, res)
{
var shopit_instance = new shopit();
return shopit_instance.viewCatalogue(req,res);
});
app.get('/items/:id', function (req, res)
{
var shopit_instance = new shopit();
return shopit_instance.viewItem(req,res);
});
//Using CheckOut Module
app.get('/checkout/',function(req,res)
{
var checkout_instance = new checkout();
return checkout_instance.checkout(req,res);
});
app.post('/checkout/confirm/',function(req,res)
{
var checkout_instance = new checkout();
return checkout_instance.checkoutOrder(req,res);
});
//Seller Functoins handled addToCart
require('./lib/seller')(app,connection);