공태현

Implement API for user register, login and logout

1 +package-lock.json
2 +/node_modules/
...\ No newline at end of file ...\ No newline at end of file
1 +const { json } = require('express/lib/response');
1 const mongoose = require('mongoose'); 2 const mongoose = require('mongoose');
2 3
3 const userSchema = new mongoose.Schema({ 4 const userSchema = new mongoose.Schema({
4 name : {type : String, required : true, unique : true, }, 5 name : {type : String, required : true, unique : true, },
5 password : {type : String, required : true, trim : true}, 6 password : {type : String, required : true, trim : true},
7 + total_squart : {type : Number, default : 0},
8 + today_squart : {type : Number, default : 0},
9 +
6 }); 10 });
7 11
12 +userSchema.methods.passwordCheck = function(password, cb) {
13 + if (password === this.password)
14 + cb(null, isMatch);
15 +}
16 +
17 +
18 +
19 +const User = mongoose.model('squartuser', userSchema )
20 +module.exports = {User};
8 21
9 -module.exports = mongoose.model('squartuser', userSchema )
10 22
......
...@@ -4,6 +4,25 @@ ...@@ -4,6 +4,25 @@
4 "lockfileVersion": 1, 4 "lockfileVersion": 1,
5 "requires": true, 5 "requires": true,
6 "dependencies": { 6 "dependencies": {
7 + "@types/node": {
8 + "version": "17.0.36",
9 + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.36.tgz",
10 + "integrity": "sha512-V3orv+ggDsWVHP99K3JlwtH20R7J4IhI1Kksgc+64q5VxgfRkQG8Ws3MFm/FZOKDYGy9feGFlZ70/HpCNe9QaA=="
11 + },
12 + "@types/webidl-conversions": {
13 + "version": "6.1.1",
14 + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-6.1.1.tgz",
15 + "integrity": "sha512-XAahCdThVuCFDQLT7R7Pk/vqeObFNL3YqRyFZg+AqAP/W1/w3xHaIxuW7WszQqTbIBOPRcItYJIou3i/mppu3Q=="
16 + },
17 + "@types/whatwg-url": {
18 + "version": "8.2.1",
19 + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.1.tgz",
20 + "integrity": "sha512-2YubE1sjj5ifxievI5Ge1sckb9k/Er66HyR2c+3+I6VDUUg1TLPdYYTEbQ+DjRkS4nTxMJhgWfSfMRD2sl2EYQ==",
21 + "requires": {
22 + "@types/node": "*",
23 + "@types/webidl-conversions": "*"
24 + }
25 + },
7 "accepts": { 26 "accepts": {
8 "version": "1.3.8", 27 "version": "1.3.8",
9 "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", 28 "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
...@@ -13,11 +32,26 @@ ...@@ -13,11 +32,26 @@
13 "negotiator": "0.6.3" 32 "negotiator": "0.6.3"
14 } 33 }
15 }, 34 },
35 + "any-promise": {
36 + "version": "1.3.0",
37 + "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
38 + "integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A=="
39 + },
16 "array-flatten": { 40 "array-flatten": {
17 "version": "1.1.1", 41 "version": "1.1.1",
18 "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", 42 "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
19 "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" 43 "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg=="
20 }, 44 },
45 + "base64-js": {
46 + "version": "1.5.1",
47 + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
48 + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
49 + },
50 + "base64-url": {
51 + "version": "1.3.3",
52 + "resolved": "https://registry.npmjs.org/base64-url/-/base64-url-1.3.3.tgz",
53 + "integrity": "sha512-UiVPRwO/m133KIQrOEIqO07D8jaYjFIx7/lYRWTRVR23tDSn00Ves6A+Bk0eLmhyz6IJGSFlNCKUuUBO2ssytA=="
54 + },
21 "body-parser": { 55 "body-parser": {
22 "version": "1.20.0", 56 "version": "1.20.0",
23 "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.0.tgz", 57 "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.0.tgz",
...@@ -37,6 +71,23 @@ ...@@ -37,6 +71,23 @@
37 "unpipe": "1.0.0" 71 "unpipe": "1.0.0"
38 } 72 }
39 }, 73 },
74 + "bson": {
75 + "version": "4.6.4",
76 + "resolved": "https://registry.npmjs.org/bson/-/bson-4.6.4.tgz",
77 + "integrity": "sha512-TdQ3FzguAu5HKPPlr0kYQCyrYUYh8tFM+CMTpxjNzVzxeiJY00Rtuj3LXLHSgiGvmaWlZ8PE+4KyM2thqE38pQ==",
78 + "requires": {
79 + "buffer": "^5.6.0"
80 + }
81 + },
82 + "buffer": {
83 + "version": "5.7.1",
84 + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
85 + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
86 + "requires": {
87 + "base64-js": "^1.3.1",
88 + "ieee754": "^1.1.13"
89 + }
90 + },
40 "bytes": { 91 "bytes": {
41 "version": "3.1.2", 92 "version": "3.1.2",
42 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", 93 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
...@@ -74,6 +125,11 @@ ...@@ -74,6 +125,11 @@
74 "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", 125 "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
75 "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" 126 "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
76 }, 127 },
128 + "crc": {
129 + "version": "3.0.0",
130 + "resolved": "https://registry.npmjs.org/crc/-/crc-3.0.0.tgz",
131 + "integrity": "sha512-+AjruG0m/tAAr6vckAT/fRlIk59IjTfdOisWu6P+Q7+BUaD1PYDeYaQKkO1hkBbv4rFDtwIZpvnbtPC/OF/W1w=="
132 + },
77 "debug": { 133 "debug": {
78 "version": "2.6.9", 134 "version": "2.6.9",
79 "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 135 "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
...@@ -82,6 +138,11 @@ ...@@ -82,6 +138,11 @@
82 "ms": "2.0.0" 138 "ms": "2.0.0"
83 } 139 }
84 }, 140 },
141 + "denque": {
142 + "version": "2.0.1",
143 + "resolved": "https://registry.npmjs.org/denque/-/denque-2.0.1.tgz",
144 + "integrity": "sha512-tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ=="
145 + },
85 "depd": { 146 "depd": {
86 "version": "2.0.0", 147 "version": "2.0.0",
87 "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", 148 "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
...@@ -150,6 +211,28 @@ ...@@ -150,6 +211,28 @@
150 "vary": "~1.1.2" 211 "vary": "~1.1.2"
151 } 212 }
152 }, 213 },
214 + "express-session": {
215 + "version": "1.17.3",
216 + "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
217 + "integrity": "sha512-4+otWXlShYlG1Ma+2Jnn+xgKUZTMJ5QD3YvfilX3AcocOAbIkVylSWEklzALe/+Pu4qV6TYBj5GwOBFfdKqLBw==",
218 + "requires": {
219 + "cookie": "0.4.2",
220 + "cookie-signature": "1.0.6",
221 + "debug": "2.6.9",
222 + "depd": "~2.0.0",
223 + "on-headers": "~1.0.2",
224 + "parseurl": "~1.3.3",
225 + "safe-buffer": "5.2.1",
226 + "uid-safe": "~2.1.5"
227 + },
228 + "dependencies": {
229 + "cookie": {
230 + "version": "0.4.2",
231 + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
232 + "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA=="
233 + }
234 + }
235 + },
153 "finalhandler": { 236 "finalhandler": {
154 "version": "1.2.0", 237 "version": "1.2.0",
155 "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", 238 "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
...@@ -222,21 +305,42 @@ ...@@ -222,21 +305,42 @@
222 "safer-buffer": ">= 2.1.2 < 3" 305 "safer-buffer": ">= 2.1.2 < 3"
223 } 306 }
224 }, 307 },
308 + "ieee754": {
309 + "version": "1.2.1",
310 + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
311 + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="
312 + },
225 "inherits": { 313 "inherits": {
226 "version": "2.0.4", 314 "version": "2.0.4",
227 "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 315 "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
228 "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 316 "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
229 }, 317 },
318 + "ip": {
319 + "version": "1.1.8",
320 + "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.8.tgz",
321 + "integrity": "sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg=="
322 + },
230 "ipaddr.js": { 323 "ipaddr.js": {
231 "version": "1.9.1", 324 "version": "1.9.1",
232 "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", 325 "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
233 "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" 326 "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g=="
234 }, 327 },
328 + "kareem": {
329 + "version": "2.3.5",
330 + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.5.tgz",
331 + "integrity": "sha512-qxCyQtp3ioawkiRNQr/v8xw9KIviMSSNmy+63Wubj7KmMn3g7noRXIZB4vPCAP+ETi2SR8eH6CvmlKZuGpoHOg=="
332 + },
235 "media-typer": { 333 "media-typer": {
236 "version": "0.3.0", 334 "version": "0.3.0",
237 "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 335 "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
238 "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" 336 "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
239 }, 337 },
338 + "memory-pager": {
339 + "version": "1.5.0",
340 + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
341 + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==",
342 + "optional": true
343 + },
240 "merge-descriptors": { 344 "merge-descriptors": {
241 "version": "1.0.1", 345 "version": "1.0.1",
242 "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", 346 "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
...@@ -265,11 +369,164 @@ ...@@ -265,11 +369,164 @@
265 "mime-db": "1.52.0" 369 "mime-db": "1.52.0"
266 } 370 }
267 }, 371 },
372 + "mongodb": {
373 + "version": "4.5.0",
374 + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.5.0.tgz",
375 + "integrity": "sha512-A2l8MjEpKojnhbCM0MK3+UOGUSGvTNNSv7AkP1fsT7tkambrkkqN/5F2y+PhzsV0Nbv58u04TETpkaSEdI2zKA==",
376 + "requires": {
377 + "bson": "^4.6.2",
378 + "denque": "^2.0.1",
379 + "mongodb-connection-string-url": "^2.5.2",
380 + "saslprep": "^1.0.3",
381 + "socks": "^2.6.2"
382 + }
383 + },
384 + "mongodb-connection-string-url": {
385 + "version": "2.5.2",
386 + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.5.2.tgz",
387 + "integrity": "sha512-tWDyIG8cQlI5k3skB6ywaEA5F9f5OntrKKsT/Lteub2zgwSUlhqEN2inGgBTm8bpYJf8QYBdA/5naz65XDpczA==",
388 + "requires": {
389 + "@types/whatwg-url": "^8.2.1",
390 + "whatwg-url": "^11.0.0"
391 + }
392 + },
393 + "mongoose": {
394 + "version": "6.3.4",
395 + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.3.4.tgz",
396 + "integrity": "sha512-UP0azyGMdY+2YNbJUHeHhnVw5vPzCqs4GQDUwHkilif/rwmSZktUQhQWMp1pUgRNeF2JC30vWGLrInZxD7K/Qw==",
397 + "requires": {
398 + "bson": "^4.6.2",
399 + "kareem": "2.3.5",
400 + "mongodb": "4.5.0",
401 + "mpath": "0.9.0",
402 + "mquery": "4.0.3",
403 + "ms": "2.1.3",
404 + "sift": "16.0.0"
405 + },
406 + "dependencies": {
407 + "ms": {
408 + "version": "2.1.3",
409 + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
410 + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
411 + }
412 + }
413 + },
414 + "mongoose-session": {
415 + "version": "0.0.4",
416 + "resolved": "https://registry.npmjs.org/mongoose-session/-/mongoose-session-0.0.4.tgz",
417 + "integrity": "sha512-nSRGIoC8V+V1R+HkyO6mkZTdc2k2XrNjIxPlWxrbDKkIdSVRlD3iDC0XbUwaX86LNiFv91XZ8hTVglyaW8iBPA==",
418 + "requires": {
419 + "express-session": "~1.8.2"
420 + },
421 + "dependencies": {
422 + "cookie": {
423 + "version": "0.1.2",
424 + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.1.2.tgz",
425 + "integrity": "sha512-+mHmWbhevLwkiBf7QcbZXHr0v4ZQQ/OgHk3fsQHrsMMiGzuvAmU/YMUR+ZfrO/BLAGIWFfx2Z7Oyso0tZR/wiA=="
426 + },
427 + "cookie-signature": {
428 + "version": "1.0.5",
429 + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.5.tgz",
430 + "integrity": "sha512-Ym05XFKVD+EOB43QU3ovI/KvqFo5MP4BGsH+SkAMn2mdjLj2W4bOSyNsw1Ik1gI7CyDtR9Ae2TUFHexgaiEuZg=="
431 + },
432 + "debug": {
433 + "version": "2.0.0",
434 + "resolved": "https://registry.npmjs.org/debug/-/debug-2.0.0.tgz",
435 + "integrity": "sha512-jRxFR0Fb657ikmm6IjHY32v/Nqp9Ndcx4LBISXPfpguNaHh5JJnb+x37qalKPTu4fxMFnVBIyEGi72mmvl0BCw==",
436 + "requires": {
437 + "ms": "0.6.2"
438 + }
439 + },
440 + "depd": {
441 + "version": "0.4.5",
442 + "resolved": "https://registry.npmjs.org/depd/-/depd-0.4.5.tgz",
443 + "integrity": "sha512-MyQx8POntp7sey9ghPezYB5gIKSbcce5pkoHdFmDYkiOcsE5f5yLLBzv8Qcs9Ll1hPgmEOfIae51n4Fa7l3zxw=="
444 + },
445 + "express-session": {
446 + "version": "1.8.2",
447 + "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.8.2.tgz",
448 + "integrity": "sha512-0vM/0QTrmStRD8AqAlWZTDraTuPhG5uTUY4RhT9wbEfmQubqc8LUQ4mnd1mnNx0HaoQ1gpPMlkJcTXeyjxigLA==",
449 + "requires": {
450 + "cookie": "0.1.2",
451 + "cookie-signature": "1.0.5",
452 + "crc": "3.0.0",
453 + "debug": "~2.0.0",
454 + "depd": "0.4.5",
455 + "on-headers": "~1.0.0",
456 + "parseurl": "~1.3.0",
457 + "uid-safe": "1.0.1",
458 + "utils-merge": "1.0.0"
459 + }
460 + },
461 + "ms": {
462 + "version": "0.6.2",
463 + "resolved": "https://registry.npmjs.org/ms/-/ms-0.6.2.tgz",
464 + "integrity": "sha512-/pc3eh7TWorTtbvXg8je4GvrvEqCfH7PA3P7iW01yL2E53FKixzgMBaQi0NOPbMJqY34cBSvR0tZtmlTkdUG4A=="
465 + },
466 + "uid-safe": {
467 + "version": "1.0.1",
468 + "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-1.0.1.tgz",
469 + "integrity": "sha1-W9FIRgouhPVPGT/SA1LIw9feasg=",
470 + "requires": {
471 + "base64-url": "1",
472 + "mz": "1"
473 + }
474 + },
475 + "utils-merge": {
476 + "version": "1.0.0",
477 + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz",
478 + "integrity": "sha1-ApT7kiu5N1FTVBxPcJYjHyh8ivg="
479 + }
480 + }
481 + },
482 + "mpath": {
483 + "version": "0.9.0",
484 + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz",
485 + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew=="
486 + },
487 + "mquery": {
488 + "version": "4.0.3",
489 + "resolved": "https://registry.npmjs.org/mquery/-/mquery-4.0.3.tgz",
490 + "integrity": "sha512-J5heI+P08I6VJ2Ky3+33IpCdAvlYGTSUjwTPxkAr8i8EoduPMBX2OY/wa3IKZIQl7MU4SbFk8ndgSKyB/cl1zA==",
491 + "requires": {
492 + "debug": "4.x"
493 + },
494 + "dependencies": {
495 + "debug": {
496 + "version": "4.3.4",
497 + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
498 + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
499 + "requires": {
500 + "ms": "2.1.2"
501 + }
502 + },
503 + "ms": {
504 + "version": "2.1.2",
505 + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
506 + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
507 + }
508 + }
509 + },
268 "ms": { 510 "ms": {
269 "version": "2.0.0", 511 "version": "2.0.0",
270 "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 512 "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
271 "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 513 "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
272 }, 514 },
515 + "mz": {
516 + "version": "1.3.0",
517 + "resolved": "https://registry.npmjs.org/mz/-/mz-1.3.0.tgz",
518 + "integrity": "sha512-x+R7YSsEySSpV5uEB+C47JTmxv+YKKNsW3W+hjvq8NbLn8ntLgYXGrR5RjQ3Fs0e7Chw8Rp/1e5eo0n5LP76cw==",
519 + "requires": {
520 + "native-or-bluebird": "1",
521 + "thenify": "3",
522 + "thenify-all": "1"
523 + }
524 + },
525 + "native-or-bluebird": {
526 + "version": "1.2.0",
527 + "resolved": "https://registry.npmjs.org/native-or-bluebird/-/native-or-bluebird-1.2.0.tgz",
528 + "integrity": "sha512-0SH8UubxDfe382eYiwmd12qxAbiWGzlGZv6CkMA+DPojWa/Y0oH4hE0lRtFfFgJmPQFyKXeB8XxPbZz6TvvKaQ=="
529 + },
273 "negotiator": { 530 "negotiator": {
274 "version": "0.6.3", 531 "version": "0.6.3",
275 "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", 532 "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
...@@ -288,6 +545,11 @@ ...@@ -288,6 +545,11 @@
288 "ee-first": "1.1.1" 545 "ee-first": "1.1.1"
289 } 546 }
290 }, 547 },
548 + "on-headers": {
549 + "version": "1.0.2",
550 + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
551 + "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA=="
552 + },
291 "parseurl": { 553 "parseurl": {
292 "version": "1.3.3", 554 "version": "1.3.3",
293 "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", 555 "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
...@@ -307,6 +569,11 @@ ...@@ -307,6 +569,11 @@
307 "ipaddr.js": "1.9.1" 569 "ipaddr.js": "1.9.1"
308 } 570 }
309 }, 571 },
572 + "punycode": {
573 + "version": "2.1.1",
574 + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
575 + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
576 + },
310 "qs": { 577 "qs": {
311 "version": "6.10.3", 578 "version": "6.10.3",
312 "resolved": "https://registry.npmjs.org/qs/-/qs-6.10.3.tgz", 579 "resolved": "https://registry.npmjs.org/qs/-/qs-6.10.3.tgz",
...@@ -315,6 +582,11 @@ ...@@ -315,6 +582,11 @@
315 "side-channel": "^1.0.4" 582 "side-channel": "^1.0.4"
316 } 583 }
317 }, 584 },
585 + "random-bytes": {
586 + "version": "1.0.0",
587 + "resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",
588 + "integrity": "sha512-iv7LhNVO047HzYR3InF6pUcUsPQiHTM1Qal51DcGSuZFBil1aBBWG5eHPNek7bvILMaYJ/8RU1e8w1AMdHmLQQ=="
589 + },
318 "range-parser": { 590 "range-parser": {
319 "version": "1.2.1", 591 "version": "1.2.1",
320 "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", 592 "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
...@@ -341,6 +613,15 @@ ...@@ -341,6 +613,15 @@
341 "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 613 "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
342 "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 614 "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
343 }, 615 },
616 + "saslprep": {
617 + "version": "1.0.3",
618 + "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz",
619 + "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==",
620 + "optional": true,
621 + "requires": {
622 + "sparse-bitfield": "^3.0.3"
623 + }
624 + },
344 "send": { 625 "send": {
345 "version": "0.18.0", 626 "version": "0.18.0",
346 "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", 627 "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz",
...@@ -394,16 +675,68 @@ ...@@ -394,16 +675,68 @@
394 "object-inspect": "^1.9.0" 675 "object-inspect": "^1.9.0"
395 } 676 }
396 }, 677 },
678 + "sift": {
679 + "version": "16.0.0",
680 + "resolved": "https://registry.npmjs.org/sift/-/sift-16.0.0.tgz",
681 + "integrity": "sha512-ILTjdP2Mv9V1kIxWMXeMTIRbOBrqKc4JAXmFMnFq3fKeyQ2Qwa3Dw1ubcye3vR+Y6ofA0b9gNDr/y2t6eUeIzQ=="
682 + },
683 + "smart-buffer": {
684 + "version": "4.2.0",
685 + "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
686 + "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg=="
687 + },
688 + "socks": {
689 + "version": "2.6.2",
690 + "resolved": "https://registry.npmjs.org/socks/-/socks-2.6.2.tgz",
691 + "integrity": "sha512-zDZhHhZRY9PxRruRMR7kMhnf3I8hDs4S3f9RecfnGxvcBHQcKcIH/oUcEWffsfl1XxdYlA7nnlGbbTvPz9D8gA==",
692 + "requires": {
693 + "ip": "^1.1.5",
694 + "smart-buffer": "^4.2.0"
695 + }
696 + },
697 + "sparse-bitfield": {
698 + "version": "3.0.3",
699 + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
700 + "integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=",
701 + "optional": true,
702 + "requires": {
703 + "memory-pager": "^1.0.2"
704 + }
705 + },
397 "statuses": { 706 "statuses": {
398 "version": "2.0.1", 707 "version": "2.0.1",
399 "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", 708 "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
400 "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" 709 "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ=="
401 }, 710 },
711 + "thenify": {
712 + "version": "3.3.1",
713 + "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz",
714 + "integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==",
715 + "requires": {
716 + "any-promise": "^1.0.0"
717 + }
718 + },
719 + "thenify-all": {
720 + "version": "1.6.0",
721 + "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz",
722 + "integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=",
723 + "requires": {
724 + "thenify": ">= 3.1.0 < 4"
725 + }
726 + },
402 "toidentifier": { 727 "toidentifier": {
403 "version": "1.0.1", 728 "version": "1.0.1",
404 "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", 729 "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
405 "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" 730 "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="
406 }, 731 },
732 + "tr46": {
733 + "version": "3.0.0",
734 + "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz",
735 + "integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==",
736 + "requires": {
737 + "punycode": "^2.1.1"
738 + }
739 + },
407 "type-is": { 740 "type-is": {
408 "version": "1.6.18", 741 "version": "1.6.18",
409 "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", 742 "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
...@@ -413,6 +746,14 @@ ...@@ -413,6 +746,14 @@
413 "mime-types": "~2.1.24" 746 "mime-types": "~2.1.24"
414 } 747 }
415 }, 748 },
749 + "uid-safe": {
750 + "version": "2.1.5",
751 + "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
752 + "integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==",
753 + "requires": {
754 + "random-bytes": "~1.0.0"
755 + }
756 + },
416 "unpipe": { 757 "unpipe": {
417 "version": "1.0.0", 758 "version": "1.0.0",
418 "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", 759 "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
...@@ -427,6 +768,20 @@ ...@@ -427,6 +768,20 @@
427 "version": "1.1.2", 768 "version": "1.1.2",
428 "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", 769 "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
429 "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" 770 "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
771 + },
772 + "webidl-conversions": {
773 + "version": "7.0.0",
774 + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
775 + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g=="
776 + },
777 + "whatwg-url": {
778 + "version": "11.0.0",
779 + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz",
780 + "integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==",
781 + "requires": {
782 + "tr46": "^3.0.0",
783 + "webidl-conversions": "^7.0.0"
784 + }
430 } 785 }
431 } 786 }
432 } 787 }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 "license": "ISC", 15 "license": "ISC",
16 "dependencies": { 16 "dependencies": {
17 "express": "^4.18.1", 17 "express": "^4.18.1",
18 - "mongoose": "^6.3.4" 18 + "express-session": "^1.17.3",
19 + "mongoose": "^6.3.4",
20 + "mongoose-session": "0.0.4"
19 } 21 }
20 } 22 }
......
1 const express = require('express'); 1 const express = require('express');
2 +
3 +
2 const app = express(); 4 const app = express();
5 +
6 +
3 const port = 3000 7 const port = 3000
4 8
9 +
5 app.get('/', (req,res) => { 10 app.get('/', (req,res) => {
6 res.send("Hello World") 11 res.send("Hello World")
7 }) 12 })
...@@ -9,3 +14,102 @@ app.get('/', (req,res) => { ...@@ -9,3 +14,102 @@ app.get('/', (req,res) => {
9 app.listen(port, () => { 14 app.listen(port, () => {
10 console.log(`Listening on ${port} port`); 15 console.log(`Listening on ${port} port`);
11 }) 16 })
17 +
18 +// model/user.js
19 +const { User } = require('./model/User');
20 +const mongoose = require('mongoose');
21 +// db 연결을 위한 키 값 , 보안을 위해 최종 마스터 브런치에는 포함하지 않을 예정.
22 +mongoose.connect('mongodb+srv://kongtae:ksas9825!%40@squartusers.e2ddc.mongodb.net/?retryWrites=true&w=majority')
23 +.then(() => console.log('MongoDB connect!'))
24 +.catch(err => console.log(err))
25 +
26 +// 유저 등록 및 로그인 API
27 +
28 +// 로그인 세션 : 로그인 정보 유지.
29 +const express_session = require('express-session')
30 +app.use(express_session({
31 + secret : "@secret@number", // 암호화 키
32 + resave : false,
33 + saveUninitialized : false,
34 + store:require('mongoose-session')(mongoose),
35 + cookie : {maxAge : 6*24}
36 +}))
37 +
38 +
39 +// 등록 .
40 +app.use(express.json())
41 +app.post('/api/users/register', (req,res) => {
42 + const new_user = new User(req.body);
43 + new_user.save((err, userInfo) => {
44 + if (err) return res.json({ successs : false, err})
45 + return res.status(200).json({
46 + success : true
47 + })
48 + })
49 +})
50 +
51 +// 로그인 .
52 +app.post('/api/users/login', (req ,res) => {
53 + User.findOne({name : req.body.name}, (err, user) => {
54 + if (!user) {
55 + return res.json({
56 + loginSuccess: false,
57 + message : "이름이 일치하는 사용자가 없습니다 !"
58 + })
59 + }
60 + else if (req.body.password === user.password) {
61 + req.session.user = {
62 + user_name : req.body.name,
63 + user_password : req.body.password,
64 + }
65 + console.log(req.session.user)
66 + return res.json({
67 + loginSuccess : true,
68 + })
69 + }
70 + else {
71 + return res.json({
72 + loginSuccess : false,
73 + message : "비밀번호가 일치하지 않습니다 !"
74 + })
75 + }
76 + })
77 +})
78 +
79 +// 로그아웃
80 +app.get('/api/users/logout', (req,res) => {
81 + var session = req.session
82 + if (session.user)
83 + {
84 + req.session.destroy(err => {
85 + if (err) {
86 + console.log(err)
87 + return res.json({
88 + logoutSuccess : false
89 + })
90 + }
91 + else
92 + {
93 + console.log('로그아웃 완료')
94 + return res.json({
95 + logoutSuccess : true
96 + })
97 + }
98 + })
99 + // res.redirect('/');
100 + }
101 + else
102 + {
103 + console.log('로그인이 되어있지 않습니다.')
104 + return res.json({
105 + logoutSuccess : true,
106 + })
107 + }
108 +
109 +})
110 +
111 +// 세션 저장 확인
112 +app.get('/api/session', (req,res) => {
113 + console.log(req.session.user)
114 + return res.json({session :req.session})
115 +})
......