-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
150 lines (134 loc) · 3.54 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
require('dotenv').config()
var express = require('express') //necessary modules required
var path = require('path')
var app = express()
var nodemailer = require('nodemailer');
//body parser and database connectivity
app.use(express.static(path.join(__dirname,'public')));
app.use(express.urlencoded({extended: true}));
app.use(express.json());
app.use(function (req, res, next) {
next()
})
var mongoose = require('mongoose');
var schema = mongoose.Schema;
var ngodb = 'mongodb://localhost/NGOs';
mongoose.connect(ngodb);
mongoose.connection.on('error',(err) => {
console.log('DB connection Error');
})
mongoose.connection.on('connected',(err) => {
useNewUrlParser: true;
console.log('DB connected');
})
//Schemas Defined
//NGO Schema
var ngoSchema = new mongoose.Schema({
nGOName: String,
filingPersonName: String,
email: String,
address: String,
ngostate: String,
employement: String,
experience: String,
contactno: String,
})
//Victim Schema
var VictimSchema = new mongoose.Schema({
victim_name: String,
gender: String,
age: String,
contactno: String,
email: String,
address: String,
description: String,
state: String,
issueFacing: String,
abuse_status: String,
extent_abuse: String,
criminalName: String,
relationWithCriminal: String,
})
//RF Schema
var ReportAsAFriendSchema = new mongoose.Schema({
rfName: String,
age: String,
contactno: String,
email: String,
address: String,
victim_name: String,
victim_number: String,
relationshipWithVictim: String,
description: String,
})
var ngo = mongoose.model('ngo', ngoSchema);
var victim = mongoose.model('victims',VictimSchema);
var reporter = mongoose.model('friendreport',ReportAsAFriendSchema);
app.post('/addNgo',function(req,res) //Add NGO Request
{
var obj = req.body;
console.log(obj);
ngo.create(obj,function(error,result)
{
if(error)
throw err;
else
{
res.sendFile(path.join(__dirname + '/public/index.html')); }
})
})
app.post('/addVictim',function(req,res) //Add Victim Request
{
var obj = req.body;
victim.create(obj,function(error,result)
{
if(error)
throw err;
else
{
ngo.find({ state : obj.state}).then(data => {console.log(data)});
res.sendFile(path.join(__dirname + '/public/index.html')); }
})
})
app.post('/Rf',function(req,res) //Friend Report Request
{
var obj = req.body;
reporter.create(obj,function(error,result)
{
if(error)
throw err;
else
{
res.sendFile(path.join(__dirname + '/public/Victim.html')); }
})
})
app.post('/mail',function(req,res) //mail function
{
var obj = req.body;
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL,
pass: process.env.PASSWORD
}
});
var mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Domestic Violence Contact Form',
text: "You have got a contact request from: " + req.body.username + "\n" + " From SHOUTUP\nThe First Name is: " + req.body.firstName + "\n" + " Last Name is: " + req.body.lastName + "\nThe subject is: " + req.body.subject + "\nThe message is: " + req.body.message
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.res);
res.sendFile(path.join(__dirname + '/public/index.html'));
}
});
})
//Server Running Confirmation
app.listen(3000,function()
{
console.log("Running on port 3000");
});