-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
101 lines (82 loc) · 2.23 KB
/
app.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
const express=require('express');
const app=express();
const bodyParser=require('body-parser');
const passport=require('passport');
const mongoose=require('mongoose');
const flash=require('connect-flash');
const session=require('express-session');
const passportSet=require('./config/passport-setup');
require('./config/passport-setup-local')(passport);
const nodemailer=require('nodemailer');
const Order=require('./models/Order');
require('dotenv').config();
// Happy Coading ... project completed
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL,
pass: process.env.PASSWORD
}
});
mongoose.connect(process.env.MONGO,{
useNewUrlParser: true,
useUnifiedTopology: true
});
app.set('view engine','ejs');
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.use(express.static('public'))
app.use(session({
secret: 'secret',
resave: true,
saveUninitialized: true,
}))
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use((req,res,next)=>{
res.locals.success_msg=req.flash('success_msg');
res.locals.error =req.flash('error');
res.locals.chat=req.user;
next();
})
app.use('/auth',require('./routes/auth-routes'));
app.use('/user',require('./routes/user-routes'));
app.get('/',(req,res)=>{
res.render('shop-contomer');
})
app.post('/api/order',(req,res)=>{
const {orders,to,from} = req.body;
const mailOptions = {
from: '[email protected]',
to: from.email,
subject: "Order Recieved",
text: `Dear ${from.name},
We Have Recieved your order and we are processing it
Please wait for the order to be confirmed from
shop side`
};
transporter.sendMail(mailOptions,(err,data)=>{
if(err){
console.log(err);
}else{
console.log('email sent!!!',data);
}
})
const order=new Order({
order:orders,
to:to.id,
from:from.id,
fromName: from.name,
fromLocation: from.location,
fromEmail:from.email
})
order.save().then((data)=>{
res.send(data);
})
})
const PORT=process.env.PORT || 4000;
const server=app.listen(PORT,function(){
console.log(`running on port number ${PORT}`);
});