/
server.js
194 lines (158 loc) · 5.96 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
const express = require("express");
const bodyParser = require("body-parser");
const nodemailer = require("nodemailer");
const creds = require("./config.js");
const mongoose = require("mongoose");
const passport = require("passport");
const path = require('path')
const users = require("./routes/api/users");
const eventfuls = require("./routes/api/eventfuls");
const app = express();
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: false
})
);
// DB Config
const db = require('./config/keys').mongoURI;
// Connect to MongoDB
mongoose
.connect(
db,
{ useNewUrlParser: true }
)
.then(() => console.log("MongoDB Connected"))
.catch(err => console.log(err));
// Passport middleware
app.use(passport.initialize());
// Passport Config
require('./config/passport')(passport);
// Use Routes
app.use('/api/users', users);
app.use('/api/eventfuls', eventfuls);
app.use(express.static('client/build'));
// create reusable transporter object using the default SMTP transport
let transport = {
host: "smtp.gmail.com",
auth: {
user: creds.USER,
pass: creds.PASS
}
};
var transporter = nodemailer.createTransport(transport);
transporter.verify((error, success) => {
if (error) {
console.log(error);
} else {
console.log('Server is ready to take messages');
}
});
app.use((request, response, next) => {
response.header("Access-Control-Allow-Origin", "*");
response.header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
response.header("Access-Control-Allow-Headers", "Content-Type");
next();
});
app.post("/sendcontact", (req, res, next) => {
console.log("at app.post!!!!!!!!!!!!!!!!!!!")
var first_name = req.body.first_name;
var last_name = req.body.last_name;
var phone = req.body.phone;
var email = req.body.email;
var comments = req.body.comments;
// setup email data with unicode symbols
let mailOptions = { from: `${first_name} ${last_name}`, to: "info@lovechangingtheworld.org", subject: `LCTW WEBSITE Add ${first_name} ${last_name} to Mailing List!`, text: `Name: ${first_name} ${last_name} \nPhone: ${phone} \nEmail: ${email} \nMessage: ${comments}` };
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, data) => {
console.log("at sendMAIL!!!!!!!!!!!!!!!!!!!");
if (error) {
return console.log(error);
} else {
console.log("Message sent!")
res.json({ msg: "success" });
}
});
});
app.post("/sendsponsor", (req, res, next) => {
var first_name = req.body.first_name;
var last_name = req.body.last_name;
var phone = req.body.phone;
var email = req.body.email;
var organization = req.body.organization;
let mailOptions = { from: `${first_name} ${last_name}`, to: "info@lovechangingtheworld.org", subject: `LCTW WEBSITE ${first_name} ${last_name} wants to become a sponsor!`, text: `Name: ${first_name} ${last_name} \nPhone: ${phone} \nEmail: ${email} \nOrganization: ${organization}` };
transporter.sendMail(mailOptions, (error, data) => {
if (error) {
return console.log(error);
} else {
console.log("Message sent!")
res.json({ msg: "success" });
}
});
});
app.post("/sendvolunteer", (req, res, next) => {
var first_name = req.body.first_name;
var last_name = req.body.last_name;
var phone = req.body.phone;
var email = req.body.email;
var experience = req.body.experience;
let mailOptions = { from: `${first_name} ${last_name}`, to: "info@lovechangingtheworld.org", subject: `LCTW WEBSITE ${first_name} ${last_name} wants to become a volunteer!`, text: `Name: ${first_name} ${last_name} \nPhone: ${phone} \nEmail: ${email} \nExperience: ${experience}` };
transporter.sendMail(mailOptions, (error, data) => {
if (error) {
return console.log(error);
} else {
console.log("Message sent!");
res.json({ msg: "success" });
}
});
});
app.post("/sendhelp", (req, res, next) => {
var first_name = req.body.first_name;
var last_name = req.body.last_name;
var phone = req.body.phone;
var email = req.body.email;
var birthday = req.body.birthday;
var location = req.body.location;
var genderage = req.body.genderage;
var shirt = req.body.shirt;
var pant = req.body.pant;
var sock = req.body.sock;
var underwear = req.body.underwear;
let mailOptions = { from: `${first_name} ${last_name}`, to: "info@lovechangingtheworld.org", subject: `LCTW WEBSITE ${first_name} ${last_name} needs supplies!`, text: `Name: ${first_name} ${last_name} \nPhone: ${phone} \nEmail: ${email} \nBirthday: ${birthday} \nArea: ${location} \nGender/Age: ${genderage} \nShirt: ${shirt} \nPant: ${pant} \nSock: ${sock} \nUnderwear: ${underwear}` };
transporter.sendMail(mailOptions, (error, data) => {
if (error) {
return console.log(error);
} else {
console.log("Message sent!");
res.json({ msg: "success" });
}
});
});
app.post("/sendfundraiser", (req, res, next) => {
var first_name = req.body.first_name;
var last_name = req.body.last_name;
var phone = req.body.phone;
var email = req.body.email;
var type = req.body.type;
var event = req.body.event;
var activities = req.body.activities;
// setup email data with unicode symbols
let mailOptions = { from: `${first_name} ${last_name}`, to: "info@lovechangingtheworld.org", subject: `LCTW WEBSITE ${first_name} ${last_name} wants to hold a fundraiser!`, text: `Name: ${first_name} ${last_name} \nPhone: ${phone} \nEmail: ${email} \nType: ${type} \nEvent: ${event} \nActivities: ${activities}` };
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, data) => {
if (error) {
return console.log(error);
} else {
console.log("Message sent!")
res.json({ msg: "success" });
}
});
});
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html")
);
});
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}!`);
});