-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
699 lines (622 loc) · 20.3 KB
/
index.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
var express = require("express");
var mysql = require("mysql2");
var fileuploader = require("express-fileupload");
var app = express();
const cors=require("cors");
const corsConfig={
origin: "*",
Credential:true,
methods: ["GET", "POST", "PUT", "DELETE"],
}
app.options("",cors(corsConfig));
app.use(cors(corsConfig));
app.listen(2005, function () {
console.log("Server Started");
});
const nodemailer = require("nodemailer");
app.get("/", function (req, resp) {
resp.sendFile(process.cwd() + "/public/index.html");
});
app.use(express.static("public"));
app.use(fileuploader());
// app.get("/profile",function(req,resp){
// resp.sendFile(process.cwd()+"/public/profile.html");
// });
app.get("/profile-donor", function (req, resp) {
resp.sendFile(process.cwd() + "/public/profile-donor.html");
});
app.get("/avail-med", function (req, resp) {
resp.sendFile(process.cwd() + "/public/avail-med.html");
});
app.use(express.urlencoded(true));
//==========DataBase======================
var dbConfig = {
host: "127.0.0.1",
user: "root",
password: "cgg@65830",
database: "signup",
dateStrings: true
}
var dbCon = mysql.createConnection(dbConfig);
dbCon.connect(function (err) {
if (err == null)
console.log("Connected Successfully");
else
resp.send(err);
})
//======================Email Checker===========
app.get("/chk-email", function (req, resp) {
//saving data in table
//fixed //same seq. as in table
dbCon.query("select * from user where email=?", [req.query.kuchEmail], function (err, resultTable) {
if (err == null) {
if (resultTable.length == 1)
resp.send("Already Taken...");
else
resp.send("Available....!!!!");
}
else
resp.send(err);
})
})
//======================Sign Up=================
app.get("/chk-submit", function (req, resp) {
dbCon.query("insert into user(email,pwd,type1,dos,status) values(?,?,?,current_date(),1)", [req.query.kuchemail, req.query.kuchpwd, req.query.kuchtype], function (err) {
if (err == null) {
resp.send("Record Saved successfully")
transporter.sendMail(options, function (err, info) {
if (err) {
console.log(err);
return;
}
else
console.log("sent: " + info.response);
})
}
else {
resp.send(err);
}
})
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'prvbaofggfhtvqly'
}
});
const options = {
from: "[email protected]", // sender ahddress
to: req.query.kuchemail, // list of receivers
subject: "Sign Up", // Subject line
text: "You have successfully signed up ", // plain text body
html: "<h1>Congrats</h1><br><b>You have successfully signed up</b><br> Login Id =" + req.query.kuchemail + "<br>Password=" + req.query.kuchpwd,
};
})
//==================Log In================
app.get("/chk-login-submit", function (req, resp) {
dbCon.query("select * from user where email=? && pwd=?", [req.query.kuchemail, req.query.kuchpwd], function (err, resultJSONTable) {
if (err == null) {
if (resultJSONTable.length > 0) {
if (resultJSONTable[0].status == 1) {
resp.send(resultJSONTable[0].type1);
}
else {
resp.send("USER BLOCKED");
}
}
else {
resp.send("INVALID EMAIL OR PASSWORD");
}
}
else {
resp.send(err);
}
});
});
// //=================Profile==========================
// //=============Submit Profile=============
// app.post("/signup",function(req,resp){
// // resp.send("Data Reached");
// var fileName="nopic.jpg";
// if(req.files!=null)
// {
// //console.log(process.cwd());
// fileName=req.files.ppic.name;
// var path=process.cwd()+"/public/upload/"+fileName;
// req.files.ppic.mv(path);
// }
// console.log(req.files);
// var emailid=req.body.txtEmail;
// var name=req.body.txtname;
// var contact=req.body.txtcontact;
// var address=req.body.txtaddress;
// var city=req.body.combocity;
// var dob=req.body.dob;
// var gender=req.body.gender;
// var id=req.body.idproof;
// console.log(req.body);
// dbCon.query("insert into user2023 values(?,?,?,?,?,?,?,?,?)",[emailid,name,contact,address,city,dob,gender,id,fileName],function(err){
// if(err==null){
// resp.send("Record saved successfullyyyyyyy");
// }
// else{
// resp.send(err);
// }
// })
// //resp.query("Welcome"+req.body.txtEmail +" "+"Name"+req.body.txtname+" "+" Contact"+req.body.txtcontact+" "+"Adress"+req.body.txtaddress+"City"+city+"dob"+dob+"Gender"+gender+"Id"+id+"Pic"+fileName);
// });
// //======================Delete Profile=================
// app.post("/db-delete-process-secure",function(req,resp)
// {
// //saving data in table
// var emailid=req.body.txtEmail;
// //fixed //same seq. as in table
// dbCon.query("delete from user2023 where emailid=?",[emailid],function(err,result)
// {
// if(err==null)
// {
// if(result.affectedRows==1)
// resp.send("Account Removed Successssfullllyyyyyyyyyyyyyyyyyyyyyyyy!!!!!!!!!");
// else
// resp.send("Inavlid Email id");
// }
// else
// resp.send(err);
// })
// })
// //================Check Email===============
// app.get("/chk-email",function(req,resp)
// {
// //saving data in table
// //fixed //same seq. as in table
// dbCon.query("select * from user2023 where emailid=?",[req.query.kuchEmail],function(err,resultTable)
// {
// if(err==null)
// {
// if(resultTable.length==1)
// resp.send("Already Taken...");
// else
// resp.send("Available....!!!!");
// }
// else
// resp.send(err);
// })
// })
// //====================update Profile=====================
// app.post("/update-db-process-secure",function(req,resp){
// var fileName;
// if(req.files!=null)
// {
// // console.log(process.cwd());
// var fileName=req.files.ppic.name;
// var path=process.cwd()+"/public/upload/"+fileName; // location
// req.files.ppic.mv(path); // move file to required path
// }
// else
// {
// fileName=req.body.hdn;
// }
// var emailid=req.body.txtEmail;
// var name=req.body.txtname;
// var contact=req.body.txtcontact;
// var address=req.body.txtaddress;
// var city=req.body.combocity;
// var dob=req.body.dob;
// var gender=req.body.gender;
// var id=req.body.idproof;
// dbCon.query("update user2023 set name=?,contact=?,address=?,city=?,dob=?,gender=?,id=? where emailid=?",[name,contact,address,city,dob,gender,id,emailid],function(err,result){
// if(err==null){
// if(result.affectedRows==1){
// resp.send("Updated Successfully..")
// }
// else{
// resp.send("No such account exists");
// }
// }
// else{
// resp.send(err);
// }
// })
// })
// //======================search email==========================
// app.get("/get-json-record",function(req,resp)
// {
// //fixed //same seq. as in table
// dbCon.query("select * from user2023 where emailid=?",[req.query.kuchemail],function(err,resultJSONKuch)
// {
// if(err==null)
// {
// resp.send(resultJSONKuch);
// }
// else
// resp.send(err);
// })
// })
//================= Donor-Profile==========================
//=============Submit Profile=============
app.post("/submit-process", function (req, resp) {
// resp.send("Data Reached");
var fileName = "nopic.jpg";
if (req.files != null) {
//console.log(process.cwd());
fileName = req.files.ppic.name;
var path = process.cwd() + "/public/upload/" + fileName;
req.files.ppic.mv(path);
}
console.log(req.files);
var emailid = req.body.txtEmail;
var name = req.body.txtname;
var contact = req.body.txtcontact;
var address = req.body.txtaddress;
var city = req.body.combocity;
var dob = req.body.dob;
var gender = req.body.gender;
var id = req.body.idproof;
var ahours = req.body.ah + "-" + req.body.bh;
console.log(req.body);
dbCon.query("insert into donors values(?,?,?,?,?,?,?,?,?,?)", [emailid, name, contact, address, city, dob, gender, id, fileName, ahours], function (err) {
if (err == null) {
resp.send("Record saved successfullyyyyyyy");
}
else {
resp.send(err);
}
})
//resp.query("Welcome"+req.body.txtEmail +" "+"Name"+req.body.txtname+" "+" Contact"+req.body.txtcontact+" "+"Adress"+req.body.txtaddress+"City"+city+"dob"+dob+"Gender"+gender+"Id"+id+"Pic"+fileName);
});
//================Check Email===============
// app.get("/email",function(req,resp)
// {
// //saving data in table
// //fixed //same seq. as in table
// dbCon.query("select * from donors where emailid=?",[req.query.kuchEmail],function(err,resultTable)
// {
// if(err==null)
// {
// if(resultTable.length==1)
// resp.send("Already Taken...");
// else
// resp.send("Available....!!!!");
// }
// else
// resp.send(err);
// })
// })
//====================update Profile=====================
app.post("/update-process", function (req, resp) {
var fileName;
if (req.files != null) {
// console.log(process.cwd());
var fileName = req.files.ppic.name;
var path = process.cwd() + "/public/upload/" + fileName; // location
req.files.ppic.mv(path); // move file to required path
}
else {
fileName = req.body.hdn;
}
var emailid = req.body.txtEmail;
var name = req.body.txtname;
var contact = req.body.txtcontact;
var address = req.body.txtaddress;
var city = req.body.combocity;
var dob = req.body.dob;
var gender = req.body.gender;
var id = req.body.idproof;
var ahours = req.body.ah + "-" + req.body.bh;
dbCon.query("update donors set name=?,contact=?,address=?,city=?,dob=?,gender=?,fileName=?,id=?,ahours=? where emailid=?", [name, contact, address, city, dob, gender, fileName, id, ahours, emailid], function (err, result) {
if (err == null) {
if (result.affectedRows == 1) {
resp.send("Updated Successfully..")
}
else {
resp.send("No such account exists");
}
}
else {
resp.send(err);
}
})
})
//======================search email==========================
app.get("/json-record", function (req, resp) {
//fixed //same seq. as in table
dbCon.query("select * from donors where emailid=?", [req.query.kuchemail], function (err, resultJSONKuch) {
if (err == null) {
resp.send(resultJSONKuch);
}
else
resp.send(err);
})
})
//======================Avail Med.=========================
//////////////////////////
app.get("/submit", function (req, resp) {
dbCon.query("insert into medsavailable(email,med,qty,packing,expdate) values(?,?,?,?,?)", [req.query.kuchemail, req.query.kuchmed, req.query.kuchquantity, req.query.kuchpacking, req.query.kuchdoe], function (err) {
if (err == null) {
resp.send("Record Saved successfully")
}
else {
resp.send(err);
}
})
})
//==========================
// connect with the smtp
//==================Settings
app.get("/setting", function (req, resp) {
dbCon.query("update user set pwd=? where email=? && pwd=?", [req.query.kuchnewPwd, req.query.kuchemail, req.query.kucholdPwd], function (err, result) {
if (err == null) {
if (result.affectedRows == 1) {
resp.send("Updated Successfully..")
transporter.sendMail(options, function (err, info) {
if (err) {
console.log(err);
return;
}
else
console.log("sent: " + info.response);
})
}
else {
resp.send("No such account exists");
}
}
else {
resp.send(err);
}
})
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'prvbaofggfhtvqly'
}
});
const options = {
from: "[email protected]", // sender ahddress
to: req.query.kuchemail, // list of receivers
subject: "Sign Up", // Subject line
text: "Your password is successfully updated ", // plain text body
html: "<h1>Congrats</h1><br><b>Your password is successfully updated</b><br> Login Id =" + req.query.kuchemail + "<br>Password=" + req.query.kuchnewPwd,
};
})
//============================needy-Profile===========================
//=============Submit Profile=============
app.post("/send_to_server", function (req, resp) {
// resp.send("Data Reached");
var fileName = "nopic.jpg";
if (req.files != null) {
//console.log(process.cwd());
fileName = req.files.ppic.name;
var path = process.cwd() + "/public/upload/" + fileName;
req.files.ppic.mv(path);
}
console.log(req.files);
var emailid = req.body.txtEmail;
var name = req.body.txtname;
var contact = req.body.txtcontact;
var address = req.body.txtaddress;
var city = req.body.combocity;
var dob = req.body.dob;
var gender = req.body.gender;
console.log(req.body);
dbCon.query("insert into needy values(?,?,?,?,?,?,?,?)", [emailid, name, contact, address, city, dob, gender, fileName], function (err) {
if (err == null) {
resp.send("Record saved successfullyyyyyyy");
}
else {
resp.send(err);
}
})
//resp.query("Welcome"+req.body.txtEmail +" "+"Name"+req.body.txtname+" "+" Contact"+req.body.txtcontact+" "+"Adress"+req.body.txtaddress+"City"+city+"dob"+dob+"Gender"+gender+"Id"+id+"Pic"+fileName);
});
///////////////////////update=============
app.post("/update-to-server", function (req, resp) {
var fileName;
if (req.files != null) {
// console.log(process.cwd());
var fileName = req.files.ppic.name;
var path = process.cwd() + "/public/upload/" + fileName; // location
req.files.ppic.mv(path); // move file to required path
}
else {
fileName = req.body.hdn;
}
var emailid = req.body.txtEmail;
var name = req.body.txtname;
var contact = req.body.txtcontact;
var address = req.body.txtaddress;
var city = req.body.combocity;
var dob = req.body.dob;
var gender = req.body.gender;
dbCon.query("update needy set name=?,contact=?,address=?,city=?,dob=?,gender=?,fileName=? where emailid=?", [name, contact, address, city, dob, gender, fileName, emailid], function (err, result) {
if (err == null) {
if (result.affectedRows == 1) {
resp.send("Updated Successfully..")
}
else {
resp.send("No such account exists");
}
}
else {
resp.send(err);
}
})
})
///////////////json========
app.get("/json", function (req, resp) {
//fixed //same seq. as in table
dbCon.query("select * from needy where emailid=?", [req.query.kuchemail], function (err, resultJSONKuch) {
if (err == null) {
resp.send(resultJSONKuch);
}
else
resp.send(err);
})
})
// app.get("/fetch-donor-data",function(req,resp){
// // alert();
// resp.sendFile(process.cwd()+"/public/panel-donors.html");
// });
// //============
// app.get("/fetch-donor-records",function(req,resp)
// {
// //fixed //same seq. as in table
// dbCon.query("select * from donors",function(err,resultTableJSON)
// {
// if(err==null)
// resp.send(resultTableJSON);
// else
// resp.send(err);
// })
// });
app.get("/get-angular-all-records", function (req, resp) {
//fixed //same seq. as in table
dbCon.query("SELECT * FROM user ORDER BY type1 ASC;", function (err, resultTableJSON) {
if (err == null)
resp.send(resultTableJSON);
else
resp.send(err);
})
})
app.get("/do-angular-delete", function (req, resp) {
//saving data in table
var email = req.query.emailkuch;
//fixed //same seq. as in table
dbCon.query("delete from user where email=?", [email], function (err, result) {
if (err == null) {
if (result.affectedRows == 1)
resp.send("Account Removed Successssfullllyyyyyyyyyyyyyyyyyyyyyyyy!!!!!!!!!");
else
resp.send("Inavlid Email id");
}
else
resp.send(err);
})
})
///=================
app.get("/do-angular-block", function (req, resp) {
var email = req.query.emailkuch;
dbCon.query("update user set status=0 where email=? ", [email], function (err, result) {
if (err == null) {
if (result.affectedRows == 1) {
resp.send("Updated Successfully..")
}
else {
resp.send("No such account exists");
}
}
else {
resp.send(err);
}
})
})
//===================
app.get("/do-angular-resume", function (req, resp) {
var email = req.query.emailkuch;
dbCon.query("update user set status=1 where email=? ", [email], function (err, result) {
if (err == null) {
if (result.affectedRows == 1) {
resp.send("Updated Successfully..")
}
else {
resp.send("No such account exists");
}
}
else {
resp.send(err);
}
})
})
//======================donor-panel===================
app.get("/get-angular-donors-records", function (req, resp) {
//fixed //same seq. as in table
dbCon.query("select * from donors", function (err, resultTableJSON) {
if (err == null)
resp.send(resultTableJSON);
else
resp.send(err);
})
})
//======================needy-panel===================
app.get("/get-angular-needys-records", function (req, resp) {
//fixed //same seq. as in table
dbCon.query("select * from needy", function (err, resultTableJSON) {
if (err == null)
resp.send(resultTableJSON);
else
resp.send(err);
})
})
/////////////////////////////////
app.get("/fetch-donor-med-details", function (req, resp) {
var email = req.query.emailkuch;
dbCon.query("select * from medsavailable where email=?", [email], function (err, resultTableJSON) {
if (err == null)
resp.send(resultTableJSON);
else
resp.send(err);
})
})
app.get("/do-delete", function (req, resp) {
//saving data in table
var srno = req.query.srnokuch;
//fixed //same seq. as in table
dbCon.query("delete from medsavailable where srno=?", [srno], function (err, result) {
if (err == null) {
if (result.affectedRows == 1)
resp.send("Medicine deleted");
else
resp.send("No expired medicine yet");
}
else
resp.send(err);
})
})
/////////////////////////
app.get("/get-cities", function (req, resp) {
//fixed //same seq. as in table
dbCon.query("select distinct city from donors", function (err, resultTableJSON) {
if (err == null)
resp.send(resultTableJSON);
else
resp.send(err);
})
})
app.get("/get-meds", function (req, resp) {
//fixed //same seq. as in table
dbCon.query("select distinct med from medsavailable", function (err, resultTableJSON) {
if (err == null)
resp.send(resultTableJSON);
else
resp.send(err);
})
})
//////////////////////////
app.get("/do-remove", function (req, resp) {
//saving data in table
//fixed //same seq. as in table
dbCon.query("delete from medsavailable where expdate<=current_date()", function (err, result) {
if (err == null) {
if (result.affectedRows == 1)
resp.send("Medicine deleted");
else
resp.send("No expired medicine yet");
}
else
resp.send(err);
})
})
app.get("/fetch-donors", function (req, resp) {
// console.log(req.query);
var med = req.query.medKuch;
var city = req.query.cityKuch;
var query = "select * from donors inner join medsavailable on donors.emailid= medsavailable.email where medsavailable.med=? and donors.city=?";
dbCon.query(query, [med, city], function (err, resultTable) {
// console.log(resultTable+" "+err);
if (err == null)
resp.send(resultTable);
else
resp.send(err);
})
})