Browse Source

Sessions3

Rich Brown 9 months ago
parent
commit
fa2a786155
6 changed files with 352 additions and 97 deletions
  1. 204
    20
      package-lock.json
  2. 2
    1
      package.json
  3. 28
    24
      routes/authRouter.js
  4. 26
    46
      routes/createRouter.js
  5. 50
    3
      src/funcs.js
  6. 42
    3
      src/index.js

+ 204
- 20
package-lock.json View File

@@ -211,6 +211,18 @@
211 211
       "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",
212 212
       "integrity": "sha1-HjRA6RXwsSA9I3SOeO3XubW0PlY="
213 213
     },
214
+    "archetype": {
215
+      "version": "0.8.8",
216
+      "resolved": "https://registry.npmjs.org/archetype/-/archetype-0.8.8.tgz",
217
+      "integrity": "sha512-isdIbFfT3zXVan34hmxIwI8A5/8lo9MaYmwXF1iYWCnJS1GvKKnZ4GrXoOUgKdUMCiB/wdguRXeStCUQhFjexg==",
218
+      "requires": {
219
+        "lodash.clonedeep": "4.x",
220
+        "lodash.set": "4.x",
221
+        "lodash.unset": "4.x",
222
+        "mpath": "0.5.1",
223
+        "standard-error": "1.1.0"
224
+      }
225
+    },
214 226
     "argparse": {
215 227
       "version": "1.0.10",
216 228
       "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
@@ -373,12 +385,19 @@
373 385
       "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
374 386
     },
375 387
     "axios": {
376
-      "version": "0.18.0",
377
-      "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
378
-      "integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
388
+      "version": "0.19.0",
389
+      "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz",
390
+      "integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==",
379 391
       "requires": {
380
-        "follow-redirects": "^1.3.0",
381
-        "is-buffer": "^1.1.5"
392
+        "follow-redirects": "1.5.10",
393
+        "is-buffer": "^2.0.2"
394
+      },
395
+      "dependencies": {
396
+        "is-buffer": {
397
+          "version": "2.0.3",
398
+          "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
399
+          "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
400
+        }
382 401
       }
383 402
     },
384 403
     "axobject-query": {
@@ -1338,6 +1357,11 @@
1338 1357
         "electron-to-chromium": "^1.3.47"
1339 1358
       }
1340 1359
     },
1360
+    "bson": {
1361
+      "version": "1.1.1",
1362
+      "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.1.tgz",
1363
+      "integrity": "sha512-jCGVYLoYMHDkOsbwJZBCqwMHyH4c+wzgI9hG7Z6SZJRXWr+x58pdIbm2i9a/jFGCkRJqRUr8eoI7lDWa0hTkxg=="
1364
+    },
1341 1365
     "buffer": {
1342 1366
       "version": "4.9.1",
1343 1367
       "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
@@ -1670,6 +1694,15 @@
1670 1694
         "xdg-basedir": "^3.0.0"
1671 1695
       }
1672 1696
     },
1697
+    "connect-mongodb-session": {
1698
+      "version": "2.1.1",
1699
+      "resolved": "https://registry.npmjs.org/connect-mongodb-session/-/connect-mongodb-session-2.1.1.tgz",
1700
+      "integrity": "sha512-k8NF+C32tJZuR3sSFfdz56e1NKzxejWlD/X5PVYBIZQ8/dzqkMGTKxcdGXsBreU5M48WZ+vYGrJSruSRTzFu4Q==",
1701
+      "requires": {
1702
+        "archetype": "0.8.x",
1703
+        "mongodb": "~3.1.8"
1704
+      }
1705
+    },
1673 1706
     "console-browserify": {
1674 1707
       "version": "1.1.0",
1675 1708
       "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz",
@@ -3051,11 +3084,26 @@
3051 3084
       "dev": true
3052 3085
     },
3053 3086
     "follow-redirects": {
3054
-      "version": "1.7.0",
3055
-      "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.7.0.tgz",
3056
-      "integrity": "sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ==",
3087
+      "version": "1.5.10",
3088
+      "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
3089
+      "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
3057 3090
       "requires": {
3058
-        "debug": "^3.2.6"
3091
+        "debug": "=3.1.0"
3092
+      },
3093
+      "dependencies": {
3094
+        "debug": {
3095
+          "version": "3.1.0",
3096
+          "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
3097
+          "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
3098
+          "requires": {
3099
+            "ms": "2.0.0"
3100
+          }
3101
+        },
3102
+        "ms": {
3103
+          "version": "2.0.0",
3104
+          "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
3105
+          "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
3106
+        }
3059 3107
       }
3060 3108
     },
3061 3109
     "for-in": {
@@ -3129,7 +3177,8 @@
3129 3177
         },
3130 3178
         "ansi-regex": {
3131 3179
           "version": "2.1.1",
3132
-          "bundled": true
3180
+          "bundled": true,
3181
+          "optional": true
3133 3182
         },
3134 3183
         "aproba": {
3135 3184
           "version": "1.2.0",
@@ -3147,11 +3196,13 @@
3147 3196
         },
3148 3197
         "balanced-match": {
3149 3198
           "version": "1.0.0",
3150
-          "bundled": true
3199
+          "bundled": true,
3200
+          "optional": true
3151 3201
         },
3152 3202
         "brace-expansion": {
3153 3203
           "version": "1.1.11",
3154 3204
           "bundled": true,
3205
+          "optional": true,
3155 3206
           "requires": {
3156 3207
             "balanced-match": "^1.0.0",
3157 3208
             "concat-map": "0.0.1"
@@ -3164,15 +3215,18 @@
3164 3215
         },
3165 3216
         "code-point-at": {
3166 3217
           "version": "1.1.0",
3167
-          "bundled": true
3218
+          "bundled": true,
3219
+          "optional": true
3168 3220
         },
3169 3221
         "concat-map": {
3170 3222
           "version": "0.0.1",
3171
-          "bundled": true
3223
+          "bundled": true,
3224
+          "optional": true
3172 3225
         },
3173 3226
         "console-control-strings": {
3174 3227
           "version": "1.1.0",
3175
-          "bundled": true
3228
+          "bundled": true,
3229
+          "optional": true
3176 3230
         },
3177 3231
         "core-util-is": {
3178 3232
           "version": "1.0.2",
@@ -3275,7 +3329,8 @@
3275 3329
         },
3276 3330
         "inherits": {
3277 3331
           "version": "2.0.3",
3278
-          "bundled": true
3332
+          "bundled": true,
3333
+          "optional": true
3279 3334
         },
3280 3335
         "ini": {
3281 3336
           "version": "1.3.5",
@@ -3285,6 +3340,7 @@
3285 3340
         "is-fullwidth-code-point": {
3286 3341
           "version": "1.0.0",
3287 3342
           "bundled": true,
3343
+          "optional": true,
3288 3344
           "requires": {
3289 3345
             "number-is-nan": "^1.0.0"
3290 3346
           }
@@ -3297,17 +3353,20 @@
3297 3353
         "minimatch": {
3298 3354
           "version": "3.0.4",
3299 3355
           "bundled": true,
3356
+          "optional": true,
3300 3357
           "requires": {
3301 3358
             "brace-expansion": "^1.1.7"
3302 3359
           }
3303 3360
         },
3304 3361
         "minimist": {
3305 3362
           "version": "0.0.8",
3306
-          "bundled": true
3363
+          "bundled": true,
3364
+          "optional": true
3307 3365
         },
3308 3366
         "minipass": {
3309 3367
           "version": "2.3.5",
3310 3368
           "bundled": true,
3369
+          "optional": true,
3311 3370
           "requires": {
3312 3371
             "safe-buffer": "^5.1.2",
3313 3372
             "yallist": "^3.0.0"
@@ -3324,6 +3383,7 @@
3324 3383
         "mkdirp": {
3325 3384
           "version": "0.5.1",
3326 3385
           "bundled": true,
3386
+          "optional": true,
3327 3387
           "requires": {
3328 3388
             "minimist": "0.0.8"
3329 3389
           }
@@ -3396,7 +3456,8 @@
3396 3456
         },
3397 3457
         "number-is-nan": {
3398 3458
           "version": "1.0.1",
3399
-          "bundled": true
3459
+          "bundled": true,
3460
+          "optional": true
3400 3461
         },
3401 3462
         "object-assign": {
3402 3463
           "version": "4.1.1",
@@ -3406,6 +3467,7 @@
3406 3467
         "once": {
3407 3468
           "version": "1.4.0",
3408 3469
           "bundled": true,
3470
+          "optional": true,
3409 3471
           "requires": {
3410 3472
             "wrappy": "1"
3411 3473
           }
@@ -3481,7 +3543,8 @@
3481 3543
         },
3482 3544
         "safe-buffer": {
3483 3545
           "version": "5.1.2",
3484
-          "bundled": true
3546
+          "bundled": true,
3547
+          "optional": true
3485 3548
         },
3486 3549
         "safer-buffer": {
3487 3550
           "version": "2.1.2",
@@ -3511,6 +3574,7 @@
3511 3574
         "string-width": {
3512 3575
           "version": "1.0.2",
3513 3576
           "bundled": true,
3577
+          "optional": true,
3514 3578
           "requires": {
3515 3579
             "code-point-at": "^1.0.0",
3516 3580
             "is-fullwidth-code-point": "^1.0.0",
@@ -3528,6 +3592,7 @@
3528 3592
         "strip-ansi": {
3529 3593
           "version": "3.0.1",
3530 3594
           "bundled": true,
3595
+          "optional": true,
3531 3596
           "requires": {
3532 3597
             "ansi-regex": "^2.0.0"
3533 3598
           }
@@ -3566,11 +3631,13 @@
3566 3631
         },
3567 3632
         "wrappy": {
3568 3633
           "version": "1.0.2",
3569
-          "bundled": true
3634
+          "bundled": true,
3635
+          "optional": true
3570 3636
         },
3571 3637
         "yallist": {
3572 3638
           "version": "3.0.3",
3573
-          "bundled": true
3639
+          "bundled": true,
3640
+          "optional": true
3574 3641
         }
3575 3642
       }
3576 3643
     },
@@ -4444,11 +4511,26 @@
4444 4511
       "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
4445 4512
       "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
4446 4513
     },
4514
+    "lodash.clonedeep": {
4515
+      "version": "4.5.0",
4516
+      "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
4517
+      "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
4518
+    },
4519
+    "lodash.set": {
4520
+      "version": "4.3.2",
4521
+      "resolved": "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz",
4522
+      "integrity": "sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM="
4523
+    },
4447 4524
     "lodash.sortby": {
4448 4525
       "version": "4.7.0",
4449 4526
       "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
4450 4527
       "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg="
4451 4528
     },
4529
+    "lodash.unset": {
4530
+      "version": "4.5.2",
4531
+      "resolved": "https://registry.npmjs.org/lodash.unset/-/lodash.unset-4.5.2.tgz",
4532
+      "integrity": "sha1-Nw0dPoW3Kn4bDN8tJyEhMG8j5O0="
4533
+    },
4452 4534
     "longest": {
4453 4535
       "version": "1.0.1",
4454 4536
       "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
@@ -4529,6 +4611,12 @@
4529 4611
         "readable-stream": "^2.0.1"
4530 4612
       }
4531 4613
     },
4614
+    "memory-pager": {
4615
+      "version": "1.5.0",
4616
+      "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
4617
+      "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==",
4618
+      "optional": true
4619
+    },
4532 4620
     "merge-descriptors": {
4533 4621
       "version": "1.0.1",
4534 4622
       "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
@@ -4568,6 +4656,22 @@
4568 4656
         "form-data": "^2.3.2",
4569 4657
         "qs": "^6.5.2",
4570 4658
         "rel-parser": "^1.0.2"
4659
+      },
4660
+      "dependencies": {
4661
+        "axios": {
4662
+          "version": "0.18.1",
4663
+          "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz",
4664
+          "integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==",
4665
+          "requires": {
4666
+            "follow-redirects": "1.5.10",
4667
+            "is-buffer": "^2.0.2"
4668
+          }
4669
+        },
4670
+        "is-buffer": {
4671
+          "version": "2.0.3",
4672
+          "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
4673
+          "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
4674
+        }
4571 4675
       }
4572 4676
     },
4573 4677
     "miller-rabin": {
@@ -4652,6 +4756,31 @@
4652 4756
         "minimist": "0.0.8"
4653 4757
       }
4654 4758
     },
4759
+    "mongodb": {
4760
+      "version": "3.1.13",
4761
+      "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.1.13.tgz",
4762
+      "integrity": "sha512-sz2dhvBZQWf3LRNDhbd30KHVzdjZx9IKC0L+kSZ/gzYquCF5zPOgGqRz6sSCqYZtKP2ekB4nfLxhGtzGHnIKxA==",
4763
+      "requires": {
4764
+        "mongodb-core": "3.1.11",
4765
+        "safe-buffer": "^5.1.2"
4766
+      }
4767
+    },
4768
+    "mongodb-core": {
4769
+      "version": "3.1.11",
4770
+      "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.1.11.tgz",
4771
+      "integrity": "sha512-rD2US2s5qk/ckbiiGFHeu+yKYDXdJ1G87F6CG3YdaZpzdOm5zpoAZd/EKbPmFO6cQZ+XVXBXBJ660sSI0gc6qg==",
4772
+      "requires": {
4773
+        "bson": "^1.1.0",
4774
+        "require_optional": "^1.0.1",
4775
+        "safe-buffer": "^5.1.2",
4776
+        "saslprep": "^1.0.0"
4777
+      }
4778
+    },
4779
+    "mpath": {
4780
+      "version": "0.5.1",
4781
+      "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.5.1.tgz",
4782
+      "integrity": "sha512-H8OVQ+QEz82sch4wbODFOz+3YQ61FYz/z3eJ5pIdbMEaUzDqA268Wd+Vt4Paw9TJfvDgVKaayC0gBzMIw2jhsg=="
4783
+    },
4655 4784
     "ms": {
4656 4785
       "version": "2.1.1",
4657 4786
       "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
@@ -5493,6 +5622,22 @@
5493 5622
         "axios": "^0.18.0",
5494 5623
         "jsdom": "^11.12.0",
5495 5624
         "li": "^1.3.0"
5625
+      },
5626
+      "dependencies": {
5627
+        "axios": {
5628
+          "version": "0.18.1",
5629
+          "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz",
5630
+          "integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==",
5631
+          "requires": {
5632
+            "follow-redirects": "1.5.10",
5633
+            "is-buffer": "^2.0.2"
5634
+          }
5635
+        },
5636
+        "is-buffer": {
5637
+          "version": "2.0.3",
5638
+          "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
5639
+          "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
5640
+        }
5496 5641
       }
5497 5642
     },
5498 5643
     "remove-trailing-separator": {
@@ -5589,6 +5734,22 @@
5589 5734
       "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz",
5590 5735
       "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE="
5591 5736
     },
5737
+    "require_optional": {
5738
+      "version": "1.0.1",
5739
+      "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
5740
+      "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
5741
+      "requires": {
5742
+        "resolve-from": "^2.0.0",
5743
+        "semver": "^5.1.0"
5744
+      },
5745
+      "dependencies": {
5746
+        "resolve-from": {
5747
+          "version": "2.0.0",
5748
+          "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
5749
+          "integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
5750
+        }
5751
+      }
5752
+    },
5592 5753
     "resolve": {
5593 5754
       "version": "1.10.1",
5594 5755
       "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.1.tgz",
@@ -5685,6 +5846,15 @@
5685 5846
       "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
5686 5847
       "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
5687 5848
     },
5849
+    "saslprep": {
5850
+      "version": "1.0.3",
5851
+      "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz",
5852
+      "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==",
5853
+      "optional": true,
5854
+      "requires": {
5855
+        "sparse-bitfield": "^3.0.3"
5856
+      }
5857
+    },
5688 5858
     "sax": {
5689 5859
       "version": "1.2.4",
5690 5860
       "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
@@ -5984,6 +6154,15 @@
5984 6154
       "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz",
5985 6155
       "integrity": "sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM="
5986 6156
     },
6157
+    "sparse-bitfield": {
6158
+      "version": "3.0.3",
6159
+      "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
6160
+      "integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=",
6161
+      "optional": true,
6162
+      "requires": {
6163
+        "memory-pager": "^1.0.2"
6164
+      }
6165
+    },
5987 6166
     "spdx-correct": {
5988 6167
       "version": "3.1.0",
5989 6168
       "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz",
@@ -6047,6 +6226,11 @@
6047 6226
       "resolved": "https://registry.npmjs.org/stackframe/-/stackframe-1.0.4.tgz",
6048 6227
       "integrity": "sha512-to7oADIniaYwS3MhtCa/sQhrxidCCQiF/qp4/m5iN3ipf0Y7Xlri0f6eG29r08aL7JYl8n32AF3Q5GYBZ7K8vw=="
6049 6228
     },
6229
+    "standard-error": {
6230
+      "version": "1.1.0",
6231
+      "resolved": "https://registry.npmjs.org/standard-error/-/standard-error-1.1.0.tgz",
6232
+      "integrity": "sha1-I+UWj6HAggGJ5YEnAaeQWFENDTQ="
6233
+    },
6050 6234
     "static-extend": {
6051 6235
       "version": "0.1.2",
6052 6236
       "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz",

+ 2
- 1
package.json View File

@@ -13,9 +13,10 @@
13 13
   "license": "ISC",
14 14
   "dependencies": {
15 15
     "atob": "^2.1.2",
16
-    "axios": "^0.18.0",
16
+    "axios": "^0.19.0",
17 17
     "backpack-core": "^0.7.0",
18 18
     "compression": "^1.7.3",
19
+    "connect-mongodb-session": "^2.1.1",
19 20
     "cors": "^2.8.4",
20 21
     "dotenv": "^6.0.0",
21 22
     "express": "^4.16.3",

+ 28
- 24
routes/authRouter.js View File

@@ -1,37 +1,41 @@
1 1
 import express from 'express';
2
-import Micropub from 'micropub-helper';
2
+
3
+import { authUser, useCode } from '../src/funcs';
3 4
 
4 5
 const authRouter = express.Router();
5 6
 
6 7
 authRouter.get('/callback', (req, res) => {
7 8
   const { code } = req.query;
8 9
   // also me and state available here
9
-  return req.app.locals.mp
10
-    .getToken(code)
11
-    .then((token) => {
12
-      if (!token) {
13
-        res.status(401).json({ err: 'Token fail on callback', msg: null });
14
-      } else {
15
-        req.app.locals.token = token;
16
-        res.json({ err: null, msg: 'Token auth successful' });
17
-      }
18
-    })
19
-    .catch((erro) => {
20
-      console.log(erro);
21
-      res.status(400).json({ err: 'Token superfail on callback', msg: null });
22
-    });
10
+  const {
11
+    clientId, redirectUri, me, state, token, tokenEndpoint,
12
+  } = req.session;
13
+  const sessionInfoAboutUser = {
14
+    clientId, redirectUri, me, state, token, tokenEndpoint,
15
+  };
16
+  return useCode(sessionInfoAboutUser, code, req, res);
23 17
 });
24 18
 
25 19
 authRouter.post('/', (req, res) => {
26
-  const newMicropub = new Micropub({ ...req.body });
27
-  req.app.locals.mp = newMicropub;
28
-  return req.app.locals.mp
29
-    .getAuthUrl()
30
-    .then(url => res.json({ error: null, url }))
31
-    .catch(() => {
32
-      // console.log(err);
33
-      res.status(400).json({ error: 'Nope.', url: null });
34
-    });
20
+  const {
21
+    clientId, redirectUri, me, state,
22
+  } = req.body;
23
+  req.session.clientId = clientId;
24
+  req.session.redirectUri = redirectUri;
25
+  req.session.me = me;
26
+  req.session.state = state;
27
+  req.session.save();
28
+  const sessionInfoAboutUser = {
29
+    clientId, redirectUri, me, state,
30
+  };
31
+  return authUser(sessionInfoAboutUser, req, res);
32
+});
33
+
34
+authRouter.get('/cookie', (req, res) => {
35
+  const { me } = req.session;
36
+  return me
37
+    ? res.json({ error: null, me })
38
+    : res.json({ error: 'no user', me: null });
35 39
 });
36 40
 
37 41
 export default authRouter;

+ 26
- 46
routes/createRouter.js View File

@@ -4,15 +4,15 @@ import multer from 'multer';
4 4
 import fs from 'fs';
5 5
 import path from 'path';
6 6
 
7
+import { create } from '../src/funcs';
8
+
7 9
 const storage = multer.diskStorage({
8 10
   destination(req, file, cb) {
9 11
     cb(null, 'uploads/');
10 12
   },
11 13
   filename(req, file, cb) {
12 14
     const { originalname } = file;
13
-    const fiver = Math.random()
14
-      .toString(36)
15
-      .substr(2, 5);
15
+    const fiver = Math.random().toString(36).substr(2, 5);
16 16
     const ext = path.extname(originalname);
17 17
     const rootName = originalname.replace(ext, '');
18 18
     const newFilename = `${rootName}-${fiver}${ext}`;
@@ -27,41 +27,28 @@ const sanitizedFile = (file) => {
27 27
   const fileExts = ['png', 'jpg', 'jpeg', 'gif'];
28 28
   const isAllowedExt = fileExts.includes(file.originalname.split('.')[1].toLowerCase());
29 29
   const isAllowedMimeType = file.mimetype.startsWith('image/');
30
-  return isAllowedExt && isAllowedMimeType;
30
+  return (isAllowedExt && isAllowedMimeType);
31 31
 };
32
-
32
+// this route should really be called /image
33 33
 createRouter.post('/form', upload.single('file'), (req, res) => {
34
-  const {
35
-    file,
36
-    body: {
37
-      title, body, arrayOfTags, altText,
38
-    },
39
-  } = req;
34
+  const { file, body: { title, body, arrayOfTags } } = req;
40 35
   if (!sanitizedFile(file)) {
41 36
     return res.status(403).json({ error: 'not an allowed filetype', url: null });
42 37
   }
38
+  // formData smooshed array of Tags into a string. de-smoosh:
43 39
   const tags = arrayOfTags.split(',');
44
-  // sort of a jokey thing here
45 40
   if (tags.includes('do not post')) {
46 41
     return res.status(422).json({ error: 'Unprocessed. -do not post- found in tags', url: null });
47 42
   }
48
-  return req.app.locals.mp
49
-    .create(
50
-      {
51
-        h: 'entry',
52
-        name: title,
53
-        content: body,
54
-        category: tags,
55
-        altText,
56
-        photo: [fs.createReadStream(file.path)],
57
-      },
58
-      'multipart',
59
-    )
60
-    .then(url => res.json({ error: null, url }))
61
-    .catch((err) => {
62
-      console.log(err);
63
-      res.status(400).json({ error: 'micropub-helper failed; multipart', url: null });
64
-    });
43
+  const createArray = {
44
+    h: 'entry',
45
+    name: title,
46
+    content: body,
47
+    category: tags,
48
+    photo: [fs.createReadStream(file.path)],
49
+  };
50
+  const sessionInfoAboutUser = { ...req.session };
51
+  return create(sessionInfoAboutUser, createArray, 'multipart', res);
65 52
 });
66 53
 
67 54
 createRouter.post('/', (req, res) => {
@@ -74,28 +61,21 @@ createRouter.post('/', (req, res) => {
74 61
   if (!tags || tags === []) {
75 62
     tags = ['micro.blog'];
76 63
   }
77
-  // sort of a jokey thing here
78 64
   if (tags.includes('do not post')) {
79 65
     return res.status(422).json({ error: 'Unprocessed. -do not post- found in tags', url: null });
80 66
   }
67
+  const sessionInfoAboutUser = { ...req.session };
81 68
   if (title === '') {
82
-    return req.app.locals.mp
83
-      .create({ h: 'entry', content: text, category: tags }, 'form') // TODO: test categories/tags
84
-      .then(url => res.json({ error: null, url }))
85
-      .catch(() => res.status(400).json({ error: 'micropub-helper failed; form', url: null }));
69
+    const createArray = { h: 'entry', content: text, category: tags };
70
+    return create(sessionInfoAboutUser, createArray, 'form', res);
86 71
   }
87
-  return req.app.locals.mp
88
-    .create(
89
-      {
90
-        h: 'entry',
91
-        name: title, // i thought MF syntax was 'p-name' but voxpelli's formattr turns NAME to TITLE
92
-        content: text,
93
-        category: tags,
94
-      },
95
-      'multipart',
96
-    )
97
-    .then(url => res.json({ error: null, url }))
98
-    .catch(() => res.status(400).json({ error: 'micropub-helper failed; multipart', url: null }));
72
+  const createArray = {
73
+    h: 'entry',
74
+    name: title,
75
+    content: text,
76
+    category: tags,
77
+  };
78
+  return create(sessionInfoAboutUser, createArray, 'multipart', res);
99 79
 });
100 80
 
101 81
 export default createRouter;

+ 50
- 3
src/funcs.js View File

@@ -1,8 +1,9 @@
1 1
 import atob from 'atob';
2
+import Micropub from 'micropub-helper';
2 3
 
3 4
 // eslint-disable-next-line import/prefer-default-export
4 5
 export const isMicropubTokenAuthed = (req, res, next) => {
5
-  const { token } = req.app.locals;
6
+  const { token } = req.session;
6 7
   if (!token) return res.status(401).json({ error: "no token, foo'" });
7 8
 
8 9
   const base64Url = token.split('.')[1];
@@ -15,8 +16,54 @@ export const isMicropubTokenAuthed = (req, res, next) => {
15 16
 
16 17
   // eslint-disable-next-line camelcase
17 18
   if (now - twoHours > issued_at) {
18
-    req.app.locals.token = null;
19
+    req.session.token = null;
20
+    // TODO: destroy session?
19 21
     return res.status(401).json({ error: "old token, foo'" });
20 22
   }
21
-  return req.app.locals.token ? next() : res.status(403).json({ error: 'NAUGHTY' });
23
+  return req.session.token ? next() : res.status(403).json({ error: 'NAUGHTY' });
24
+};
25
+
26
+// mpOptions to create a new micropub, post options go into its create func
27
+export const create = (mpOptions, postOptions, type, res) => {
28
+  // console.log(mpOptions, '<== options sent to create func');
29
+  const mp = new Micropub({ ...mpOptions });
30
+  return mp
31
+    .create(postOptions, type)
32
+    .then(url => res.json({ error: null, url }))
33
+    .catch(() => res.status(400).json({ error: 'micropub-helper failed', url: null }));
34
+};
35
+
36
+export const authUser = (mpOptions, req, res) => {
37
+  const mp = new Micropub({ ...mpOptions });
38
+  return mp
39
+    .getAuthUrl()
40
+    .then((url) => {
41
+      // console.log(mp.options, '<== picked up options at authUser func');
42
+      req.session.tokenEndpoint = mp.options.tokenEndpoint;
43
+      req.session.micropubEndpoint = mp.options.micropubEndpoint;
44
+      req.session.save();
45
+      return res.json({ error: null, url });
46
+    })
47
+    .catch(() => {
48
+      // console.log(err);
49
+      res.status(400).json({ error: 'Nope.', url: null });
50
+    });
51
+};
52
+
53
+export const useCode = (mpOptions, code, req, res) => {
54
+  const mp = new Micropub({ ...mpOptions });
55
+  return mp
56
+    .getToken(code)
57
+    .then((token) => {
58
+      if (!token) {
59
+        res.status(401).json({ err: 'Token fail on callback', msg: null });
60
+      } else {
61
+        req.session.token = token;
62
+        res.json({ err: null, msg: 'Token auth successful' });
63
+      }
64
+    })
65
+    .catch(() => {
66
+      // console.log(erro);
67
+      res.status(400).json({ err: 'Token superfail on callback', msg: null });
68
+    });
22 69
 };

+ 42
- 3
src/index.js View File

@@ -1,6 +1,8 @@
1 1
 import express from 'express';
2 2
 import cors from 'cors';
3
-import compression from 'compression';
3
+// import compression from 'compression';
4
+import session from 'express-session';
5
+import CMS from 'connect-mongodb-session';
4 6
 
5 7
 import { blogRouter } from '../routes/blog-router';
6 8
 import { genericRouter } from '../routes/generic-notify';
@@ -13,8 +15,45 @@ import { isMicropubTokenAuthed } from './funcs';
13 15
 const port = 8086;
14 16
 const app = express();
15 17
 
16
-app.use(compression());
17
-app.use(cors());
18
+const MongoDBStore = CMS(session);
19
+const store = new MongoDBStore({
20
+  uri: `mongodb+srv://colors_admin:${process.env.MONGO_PASSWORD}@cluster0-4udef.mongodb.net/test?retryWrites=true&w=majority`,
21
+  databaseName: 'notifierDb',
22
+  collection: 'sessions',
23
+}, (error) => {
24
+  if (error) console.log('MongoDBStore connection error: ', error);
25
+});
26
+
27
+// Catch errors
28
+store.on('error', (error) => {
29
+  console.log('store error:', error);
30
+});
31
+
32
+app.set('trust proxy', 1); // trust first proxy
33
+
34
+const routesArray = ['/create', '/auth'];
35
+
36
+app.use(routesArray, session({
37
+  secret: process.env.MONGO_PASSWORD, // dumb
38
+  store,
39
+  resave: true,
40
+  saveUninitialized: true,
41
+  cookie: { secure: false, maxAge: 1000 * 60 * 60 * 3, sameSite: false },
42
+}));
43
+
44
+app.use((req, res, next) => {
45
+  console.log(req.session, '<- session string');
46
+  next();
47
+});
48
+
49
+// app.use(compression());
50
+
51
+const corsArrays = ['https://post.porknachos.com', 'http://localhost:3000', 'https://dashboard.porknachos.com'];
52
+const corsOptions = {
53
+  origin: corsArrays,
54
+  credentials: true,
55
+};
56
+app.use(cors(corsOptions));
18 57
 app.use(express.urlencoded({ extended: true }));
19 58
 app.use(express.json());
20 59