-
Notifications
You must be signed in to change notification settings - Fork 0
/
old.js
1463 lines (1302 loc) · 42.6 KB
/
old.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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//---------------------------------
function checkAPIkey(key, requiredScope) {
let hash1 = md5(key);
//verify key
return new Promise((resolve, reject) => {
let sql = `SELECT scopes FROM api_keys WHERE key = '${hash1}'`;
db.all(sql, (err, rows) => {
if (err) {
//res.status(400).json({ error: err.message });
//console.log(err.message);
reject(err.message);
}
if (rows.length <= 0) {
//res.status(400).json({ error: "API Key does not exist" });
//console.log(1);
reject("API Key does not exist");
}
if (rows.length > 1) {
//res.status(400).json({ error: "duplicate API Keys exist" });
//console.log(2);
reject("duplicate API Keys exist");
}
//verify scope
if (!hasScope(rows, requiredScope)) {
//res.status(400).json({ error: "Key scope does not allow this request" });
//console.log(3);
reject(`key scope does not contain ${requiredScope}`);
}
resolve("success");
});
});
}
function hasScope(rows, required) {
let row = rows[0];
if (!row) {
return false;
}
let scopes = row.scopes.split(",");
//console.log(scopes);
//if (required == "*") {
//master
if (
(scopes.length > 1 && scopes.includes("*")) ||
(scopes.length == 1 && scopes == "*")
) {
return true;
}
//} else if (required.includes(".")) {
//required.*
if (
(scopes.length > 1 && scopes.includes(required.split(".")[0] + ".*")) ||
(scopes.length == 1 && scopes == required.split(".")[0] + ".*")
) {
return true;
}
//required.required
if (
(scopes.length > 1 && scopes.includes(required)) ||
(scopes.length == 1 && scopes == required)
) {
return true;
}
//}
//incorrect scope or error
return false;
}
//-----------------requests---------------
/**
* @return list of api keys
*/
app.get("/api/:key/key/list", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "key.list");
} catch (err) {
res.status(400).json({ error: err });
return;
}
//get all api keys
var sql = "select * from api_keys";
var params = [];
db.all(sql, params, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
data: rows,
});
});
});
/**
* @return newly generated master key
*/
app.get("/api/:key/key/generatemaster", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "*");
} catch (err) {
res.status(400).json({ error: err });
return;
}
//generate new key
let prefix = generateApiKey({ method: "bytes", length: 7 });
let affix = generateApiKey({ method: "bytes", length: 20 });
let apikey = prefix + "." + affix;
let hash2 = md5(apikey);
var sql = `INSERT INTO api_keys (name, prefix, key, scopes) VALUES ('Master', '${prefix}', '${hash2}', '*');`;
db.run(sql, (err) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
apikey: apikey,
});
});
});
/**
* @return scopes of api key
*/
app.get("/api/:key/key/test", async (req, res) => {
let key = req.params.key;
let hash = md5(key);
//verify key
let sql = `SELECT scopes FROM api_keys WHERE key = '${hash}'`;
db.all(sql, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
if (rows.length <= 0) {
res.status(400).json({ error: "API Key does not exist" });
return;
}
if (rows.length > 1) {
res.status(400).json({ error: "duplicate API Keys exist" });
return;
}
res.json({
message: "success",
data: rows,
});
});
});
/**
* @return list of events
*/
app.get("/api/:key/event/list", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "event.list");
} catch (err) {
res.status(400).json({ error: err });
return;
}
//get all events
let sql = `SELECT * FROM events;`;
db.all(sql, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
data: rows,
});
});
});
/**
* @param body event to create
*/
app.post("/api/:key/event/create", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "event.create");
} catch (err) {
res.status(400).json({ error: err });
return;
}
//get body data
var errors = [];
var status = 0;
var statusChanged = false;
if (!req.query.name) {
errors.push("New events must have a name");
}
if (!req.query.identifier) {
errors.push("New events must have an identifer");
} else if (req.query.identifier.includes(" ")) {
errors.push("Event identifiers cannot include spaces");
} else if (req.query.identifier.length > 24) {
errors.push("Event identifiers cannot be longer than 24 characters");
}
//res.json({data: req.query});
//return;
if (req.query.status) {
if (
+req.query.status > 1 ||
+req.query.status < 0 ||
!Number.isInteger(+req.query.status)
) {
errors.push("Event status can only have values 0,1");
} else {
status = req.query.status;
statusChanged = true;
}
}
if (errors.length) {
res.status(400).json({ error: errors.join(", ") });
return;
}
//insert into events table
var additional = [];
var values = [];
if (req.query.description) {
additional.push(`description`);
values.push(`'${req.query.description}'`);
}
if (statusChanged) {
additional.push(`status`);
values.push(`'${status}'`);
}
let sql = `INSERT INTO events (name, identifier) VALUES ('${req.query.name}', '${req.query.identifier}');`;
if (additional.length > 0) {
sql = `INSERT INTO events (name, identifier, ${additional.join(
", "
)}) VALUES ('${req.query.name}', '${req.query.identifier}', ${values.join(
", "
)});`;
}
db.run(sql, (err) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
//create new table for event
let sql2 = `CREATE TABLE "event_${req.query.identifier}" (
"barcodeNum" INTEGER NOT NULL UNIQUE,
"attended" INTEGER NOT NULL DEFAULT 0,
"lastModified" TEXT,
"modifiedBy" TEXT,
FOREIGN KEY("modifiedBy") REFERENCES "api_keys"("prefix"),
FOREIGN KEY("barcodeNum") REFERENCES "users"("barcodeNum")
);`;
db.run(sql2, (err) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
});
res.json({
message: "success",
});
});
});
/**
* @param body event to create
*/
app.post("/api/:key/event/update", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "event.update");
} catch (err) {
res.status(400).json({ error: err });
return;
}
//get body data
var errors = [];
var status = 0;
var statusChanged = false;
if (!req.query.identifier) {
errors.push("Query must include an identifier property");
} else if (req.query.identifier.includes(" ")) {
errors.push("Event identifiers cannot include spaces");
} else if (req.query.identifier.length > 24) {
errors.push("Event identifiers cannot be longer than 24 characters");
}
//res.json({data: req.query});
//return;
if (req.query.status) {
if (
+req.query.status > 1 ||
+req.query.status < 0 ||
!Number.isInteger(+req.query.status)
) {
errors.push("Event status can only have values 0,1");
} else {
status = req.query.status;
statusChanged = true;
}
}
if (errors.length) {
res.status(400).json({ error: errors.join(", ") });
return;
}
var additional = [];
if (req.query.name) {
additional.push(`name = '${req.query.name}'`);
}
if (req.query.description) {
additional.push(`description = '${req.query.description}'`);
}
if (statusChanged) {
additional.push(`status = '${status}'`);
}
if (additional.length <= 0) {
res.status(400).json({ error: "Missing properties of event to update" });
return;
}
let sql = `UPDATE events SET ${additional.join(", ")} WHERE identifier = '${
req.query.identifier
}';`;
db.run(sql, (err) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
});
});
});
/**
* @param body user and event
*/
app.post("/api/:key/event/checkin", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "event.checkin");
} catch (err) {
res.status(400).json({ error: err });
return;
}
let prefix = key.split(".")[0];
//get body data
var errors = [];
if (!req.query.eventIdentifier) {
errors.push("Query must include an eventIdentifier property");
}
if (!req.query.userBarcode) {
errors.push("Query must include a userBarcode property");
}
if (errors.length) {
res.status(400).json({ error: errors.join(", ") });
return;
}
try {
//check whether event exists
let sql5 = `SELECT COUNT(*) as count FROM events WHERE identifier = '${req.query.eventIdentifier}'`;
db.all(sql5, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
if (rows[0].count <= 0) {
res.status(400).json({ error: "Event not found" });
return;
}
//check whether event is enabled
let sql5 = `SELECT status FROM events WHERE identifier = '${req.query.eventIdentifier}'`;
db.all(sql5, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
let status = rows[0].status;
if (!status) {
res.status(400).json({ error: "Event has been disabled" });
return;
} else {
//check whether user already checked in
let sql2 = `SELECT COUNT(*) as count FROM event_${req.query.eventIdentifier} WHERE barcodeNum = '${req.query.userBarcode}'`;
db.all(sql2, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
if (rows[0].count) {
let sql3 = `SELECT COUNT(*) as count FROM event_${req.query.eventIdentifier} WHERE barcodeNum = '${req.query.userBarcode}' AND attended = '1'`;
db.all(sql3, (err, rows1) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
if (rows1[0].count) {
res.status(400).json({
error: "User is already checked in for this event",
});
return;
} else {
//update exisiting checkin
let sql4 = `UPDATE event_${req.query.eventIdentifier} SET attended = '1', lastModified = strftime('%Y-%m-%d %H:%M:%S', 'now'), modifiedBy = '${prefix}' WHERE barcodeNum = '${req.query.userBarcode}';`;
db.run(sql4, (err) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
});
});
}
});
} else {
//check whether user exists
let sql7 = `SELECT COUNT(*) as count FROM users WHERE barcodeNum = '${req.query.userBarcode}';`;
db.all(sql7, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
if (rows[0].count <= 0) {
res.status(400).json({ error: "User not found" });
return;
}
//insert into event table
let sql = `INSERT INTO event_${req.query.eventIdentifier} (barcodeNum, attended, lastModified, modifiedBy) VALUES ('${req.query.userBarcode}', '1', strftime('%Y-%m-%d %H:%M:%S', 'now'), '${prefix}');`;
db.run(sql, (err) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
});
});
});
}
});
}
});
});
} catch (err) {
res.status(400).json({ error: err.message });
return;
}
});
/**
* @param body user and event
*/
app.post("/api/:key/event/uncheckin", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "event.uncheckin");
} catch (err) {
res.status(400).json({ error: err });
return;
}
let prefix = key.split(".")[0];
//get body data
var errors = [];
if (!req.query.eventIdentifier) {
errors.push("Query must include an eventIdentifier property");
}
if (!req.query.userBarcode) {
errors.push("Query must include a userBarcode property");
}
if (errors.length) {
res.status(400).json({ error: errors.join(", ") });
return;
}
//check whether event is enabled
let sql3 = `SELECT status FROM events WHERE identifier = '${req.query.eventIdentifier}'`;
db.all(sql3, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
let status = rows[0].status;
if (!status) {
res.status(400).json({ error: "Event has been disabled" });
return;
} else {
//insert into event table table
let sql = `UPDATE event_${req.query.eventIdentifier} SET attended = '0', lastModified = strftime('%Y-%m-%d %H:%M:%S', 'now'), modifiedBy = '${prefix}' WHERE barcodeNum = '${req.query.userBarcode}';`;
db.run(sql, (err) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
});
});
}
});
});
/**
* @param body user and event
*/
app.get("/api/:key/event/status", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "event.status");
} catch (err) {
res.status(400).json({ error: err });
return;
}
let prefix = key.split(".")[0];
//get body data
var errors = [];
if (!req.query.eventIdentifier) {
errors.push("Query must include an eventIdentifier property");
}
if (errors.length) {
res.status(400).json({ error: errors.join(", ") });
return;
}
//select all attending users
let sql = `SELECT COUNT(*) as count FROM event_${req.query.eventIdentifier} WHERE attended = '1'`;
db.all(sql, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
let countAttended = rows[0].count;
let sql2 = `SELECT COUNT(*) as count FROM users`;
db.all(sql2, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
let countTotal = rows[0].count;
let sql3 = `SELECT status FROM events WHERE identifier = '${req.query.eventIdentifier}'`;
db.all(sql3, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
let status = rows[0].status;
res.json({
message: "success",
data: { attended: countAttended, total: countTotal, status: status },
});
});
});
});
});
/**
* @return whether user is checked in to event
*/
app.get("/api/:key/event/checkedin", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "event.checkedin");
} catch (err) {
res.status(400).json({ error: err });
return;
}
//get body data
var errors = [];
if (!req.query.eventIdentifier) {
errors.push("Query must include an eventIdentifier property");
}
if (!req.query.userBarcode) {
errors.push("Query must include a userBarcode property");
}
if (errors.length) {
res.status(400).json({ error: errors.join(", ") });
return;
}
//get whether user is checked in
let sql = `SELECT COUNT(*) as count FROM event_${req.query.eventIdentifier} WHERE barcodeNum = '${req.query.userBarcode}' AND attended = '1';`;
db.all(sql, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
data: rows,
});
});
});
/**
* @return list of users
*/
app.get("/api/:key/user/list", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "user.list");
} catch (err) {
res.status(400).json({ error: err });
return;
}
//get all events
let sql = `SELECT * FROM users;`;
db.all(sql, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
data: rows,
});
});
});
/**
* @param body user to create
*/
app.post("/api/:key/user/create", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "user.create");
} catch (err) {
res.status(400).json({ error: err });
return;
}
//get body data
var errors = [];
if (!req.query.userName) {
errors.push("Query must include userName property");
}
if (!req.query.userEmail) {
errors.push("Query must include userEmail property");
} else if (!req.query.userEmail.includes("@")) {
errors.push("User email not in valid format");
}
if (errors.length) {
res.status(400).json({ error: errors.join(", ") });
return;
}
let barcode = generateApiKey({ length: 11, pool: "0123456789" });
//insert into users table
let sql = `INSERT INTO users (name, email, barcodeNum) VALUES ('${req.query.userName}', '${req.query.userEmail}', '${barcode}');`;
db.run(sql, (err) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
});
});
//res.json({data: barcode});
});
/**
* @param body user to create
*/
app.post("/api/:key/user/remove", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "user.create");
} catch (err) {
res.status(400).json({ error: err });
return;
}
//get body data
var errors = [];
if (!req.query.barcodeNum) {
errors.push("Query must include barcodeNum property");
}
if (errors.length) {
res.status(400).json({ error: errors.join(", ") });
return;
}
//insert into users table
let sql = `DELETE FROM users WHERE barcodeNum = '${req.query.barcodeNum}'`;
db.run(sql, (err) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
});
});
//res.json({data: barcode});
});
/**
* @param body user to create
*/
app.post("/api/:key/event/remove", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "event.create");
} catch (err) {
res.status(400).json({ error: err });
return;
}
//get body data
var errors = [];
if (!req.query.identifier) {
errors.push("Query must include identifier property");
}
if (errors.length) {
res.status(400).json({ error: errors.join(", ") });
return;
}
//insert into users table
let sql = `DELETE FROM events WHERE identifier = '${req.query.identifier}'`;
db.run(sql, (err) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
});
});
//res.json({data: barcode});
});
/**
* @param body user to update
*/
app.post("/api/:key/user/update", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "user.update");
} catch (err) {
res.status(400).json({ error: err });
return;
}
//get body data
var errors = [];
if (!req.query.barcodeNum) {
errors.push("Query must include barcodeNum property");
}
if (!req.query.userName && !req.query.userEmail) {
errors.push("Query must include userName or userEmail property");
}
if (req.query.userEmail && !req.query.userEmail.includes("@")) {
errors.push("User email not in valid format");
}
if (errors.length) {
res.status(400).json({ error: errors.join(", ") });
return;
}
var additional = [];
if (req.query.userName) {
additional.push(`name = '${req.query.userName}'`);
}
if (req.query.userEmail) {
additional.push(`email = '${req.query.userEmail}'`);
}
if (additional.length <= 0) {
res.status(400).json({ error: "Missing properties of user to update" });
return;
}
let sql = `UPDATE users SET ${additional.join(", ")} WHERE barcodeNum = '${
req.query.barcodeNum
}';`;
db.run(sql, (err) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: "success",
});
});
});
/**
* @param user barcode num
*/
app.get("/api/:key/user/email", async (req, res) => {
//check for prerequisites
let key = req.params.key;
try {
let result = await checkAPIkey(key, "user.email");
} catch (err) {
res.status(400).json({ error: err });
return;
}
if (!req.query.barcodeNum) {
res.status(400).json({ error: "Query must include barcodeNum property" });
return;
}
//get user email
let sql = `SELECT COUNT(*) as count, email FROM users WHERE barcodeNum = '${req.query.barcodeNum}';`;
db.all(sql, (err, rows) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
if (!rows[0].count) {
//barcodenum incorrect
res.status(400).json({ error: "User not found with given barcodeNum" });
return;
}
//send email with barcode
//generate qr code
//let qrcode = "";
qr.toDataURL(req.query.barcodeNum, function (err, url) {
if (err) {
res.status(400).json({ error: err });
return;
}
//console.log(url)
let transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 587,
auth: {
user: process.env.EMAIL_USERNAME,
pass: process.env.EMAIL_PASSWORD,
} /*
dkim: {
domainName: "hacklytics2022.com",
keySelector: "key1",
privateKey: fs.readFileSync("./certificates/dkim/dkim.pem", "utf8"),
cacheDir: "/tmp",
cacheTreshold: 100 * 1024,
},*/,
});
//console.log(url)
message = {
from: process.env.EMAIL_USERNAME,
to: rows[0].email,
subject: "Next Steps - Hacklytics 2022",
html: `<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:v="urn:schemas-microsoft-com:vml" lang="en">
<head>
<link rel="stylesheet" type="text/css" hs-webfonts="true"
href="https://fonts.googleapis.com/css?family=Lato|Lato:i,b,bi">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Red+Hat+Text:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap"
rel="stylesheet">
<title>Hacklytics 2022 Emailer</title>
<meta property="og:title" content="Email template">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
table {
table-layout: fixed;
}
a {
text-decoration: underline;
color: inherit;
color: blue;
}
h1 {
font-size: 32px;
}
h2 {
font-size: 28px;
font-weight: 900;
}
img {
max-width: 100%;
}
p {
font-weight: 100;
}
td {
text-align: center;
vertical-align: middle;
}
td.main {
text-align: left;
}
#email {
margin: auto;
width: 600px;
background-color: white;
}
button {
font: inherit;
background-color: rgba(32, 163, 158, 1);
border: none;
padding: 10px;
text-transform: uppercase;
letter-spacing: 2px;
font-weight: 900;
color: white;
border-radius: 5px;
box-shadow: 3px 3px #ADCEF2;
text-align: center;
}
.subtle-link {
font-size: 9px;
text-transform: uppercase;
letter-spacing: 1px;
color: #CBD6E2;
}
#applyButton {
/*position: fixed;*/
box-sizing: border-box;
width: fit-content;
/*right: 15px;*/