From a93847eaf4ff265121dadc5eb13e3546a56499f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Ckellylimmm=E2=80=9D?= <“kellylim.06@gmail.com”> Date: Sat, 19 Oct 2019 13:57:38 +0800 Subject: [PATCH 1/5] Add login and register --- index.js | 117 ++++++- package-lock.json | 683 ++++++++++++++++++++++------------------- package.json | 23 +- seed.sql | 26 ++ tables.sql | 12 + views/login.jsx | 28 ++ views/user/NewUser.jsx | 7 +- 7 files changed, 557 insertions(+), 339 deletions(-) create mode 100644 seed.sql create mode 100644 tables.sql create mode 100644 views/login.jsx diff --git a/index.js b/index.js index 4d5d595..349208f 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,10 @@ const cookieParser = require('cookie-parser'); const pg = require('pg'); +var sha256 = require('js-sha256'); + +var SALT = "tweedr"; + /** * =================================== * Configurations and set up @@ -11,9 +15,9 @@ const pg = require('pg'); */ const configs = { - user: 'akira', + user: 'kellylim', host: '127.0.0.1', - database: 'testdb', + database: 'tweedr', port: 5432, }; @@ -39,12 +43,17 @@ app.set('views', __dirname + '/views'); app.set('view engine', 'jsx'); app.engine('jsx', reactEngine); +// Set the configuration to tell express to use cookie parser +app.use(cookieParser()); + /** * =================================== * Routes * =================================== */ +// ============ Register ========= + // Root GET request (it doesn't belong in any controller file) app.get('/', (request, response) => { response.send('Welcome To Tweedr.'); @@ -55,21 +64,111 @@ app.get('/users/new', (request, response) => { }); app.post('/users', (request, response) => { + console.log(request.body); + + let hashedPassword = sha256(request.body.password + SALT); + + const queryString = 'INSERT INTO users (username, password) VALUES ($1, $2) RETURNING *'; - const queryString = 'INSERT INTO users (name, password) VALUES ($1, $2)'; const values = [ - request.body.name, - request.body.password + request.body.username, + hashedPassword, ]; // execute query - pool.query(queryString, values, (error, queryResult) => { - //response.redirect('/'); - response.send('user created'); + // pool.query(queryString, values, (err, result) => { + + // if (err) { + // console.error('query error: ', err.stack); + // response.send('query error'); + // } else { + // console.log('query result: ', result); + // //response.redirect('/'); + // response.send('user created'); + // console.log(result.rows, "JAJAJAJA"); + // } + pool.query(queryString, values, (err,result) =>{ + + if (err) { + console.error('query error:', err.stack); + response.send( 'query error' ); + } else { + console.log('query result:', result); + + + response.send( result.rows ); + } }); }); +//========== Login ============= + +app.get('/login', (request, response) => { + response.render('login'); +}) + +app.post('/login', (request, response) => { + let requestUsername = request.body.username; + let requestPassword = request.body.password; + + const queryString = "SELECT * FROM users WHERE username= '"+requestUsername+"'"; + console.log("db query", queryString); + + pool.query(queryString, (err, result) => { + + if (err) { + console.error('query error: ', err.stack); + response.send('query error'); + } else { + console.log('query result: ', result.rows); + + +if (result.rows.length > 0) { + + let hashedRequestPassword = sha256(requestPassword + SALT); + console.log("hashed request password : " + hashedRequestPassword); + + if (hashedRequestPassword === result.rows[0].password) { + let user_id = result.rows[0].id + let hashedCookie = sha256(SALT+ user_id); + + response.cookie('user_id', user_id); + response.cookie('hasLoggedIn', hashedCookie); + + response.send('LOGGING IN.....'); + } else { + response.status(403).send('wrong password'); + } + +} + +else { + response.status(403).send('NO USERNAME!'); +} + } + + }); + +}); + + +//=========== Cookies ======= + +app.get('/special', (request,response) => { + + let user_id = request.cookies['user_id']; + let hashedValue = sha256(SALT + user_id); + + +if (request.cookies['hasLoggedIn'] === hashedValue) { + response.send("LOGGED IN"); +} else { + response.redirect('/login'); +} + + +}); /** * =================================== @@ -88,4 +187,4 @@ let onClose = function(){ }; process.on('SIGTERM', onClose); -process.on('SIGINT', onClose); +process.on('SIGINT', onClose); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 50d2bd3..9ce0269 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,12 +10,12 @@ "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" }, "accepts": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", - "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", + "version": "1.3.7", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", + "integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", "requires": { - "mime-types": "~2.1.18", - "negotiator": "0.6.1" + "mime-types": "~2.1.24", + "negotiator": "0.6.2" } }, "ansi-regex": { @@ -33,11 +33,6 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, - "asap": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", - "integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=" - }, "babel-code-frame": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", @@ -696,26 +691,21 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, - "bluebird": { - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", - "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" - }, "body-parser": { - "version": "1.18.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", - "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=", + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", + "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", "requires": { - "bytes": "3.0.0", + "bytes": "3.1.0", "content-type": "~1.0.4", "debug": "2.6.9", - "depd": "~1.1.1", - "http-errors": "~1.6.2", - "iconv-lite": "0.4.19", + "depd": "~1.1.2", + "http-errors": "1.7.2", + "iconv-lite": "0.4.24", "on-finished": "~2.3.0", - "qs": "6.5.1", - "raw-body": "2.3.2", - "type-is": "~1.6.15" + "qs": "6.7.0", + "raw-body": "2.4.0", + "type-is": "~1.6.17" } }, "brace-expansion": { @@ -737,19 +727,19 @@ } }, "buffer-writer": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-1.0.1.tgz", - "integrity": "sha1-Iqk2kB4wKa/NdUfrRIfOtpejvwg=" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", + "integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==" }, "bytes": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", - "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", + "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" }, "caniuse-lite": { - "version": "1.0.30000861", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000861.tgz", - "integrity": "sha512-aeEQ4kyd41qCl8XFbCjWgVBI3EOd66M9sC43MFn0kuD/vcrNqvoIAlKon4xdp8yMCYvVjdCltI3lgArj8I6cNA==" + "version": "1.0.30000999", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000999.tgz", + "integrity": "sha512-1CUyKyecPeksKwXZvYw0tEoaMCo/RwBlXmEtN5vVnabvO0KPd9RQLcaAuR9/1F+KDMv6esmOFWlsXuzDk+8rxg==" }, "chalk": { "version": "1.1.3", @@ -764,9 +754,9 @@ } }, "commander": { - "version": "2.16.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.16.0.tgz", - "integrity": "sha512-sVXqklSaotK9at437sFlFpyOcJonxe0yST/AG9DkQKUdIE6IqGIMv4SfAQSKaJbSdVEJYItASCrBiVQHq1HQew==" + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, "concat-map": { "version": "0.0.1", @@ -774,18 +764,21 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "config-chain": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.11.tgz", - "integrity": "sha1-q6CXR9++TD5w52am5BWG4YWfxvI=", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.12.tgz", + "integrity": "sha512-a1eOIcu8+7lUInge4Rpf/n4Krkf3Dd9lqhljRzII1/Zno/kRtUWnznPO3jOKBmTEktkt3fkxisUcivoj0ebzoA==", "requires": { "ini": "^1.3.4", "proto-list": "~1.2.1" } }, "content-disposition": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", - "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", + "integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==", + "requires": { + "safe-buffer": "5.1.2" + } }, "content-type": { "version": "1.0.4", @@ -798,9 +791,12 @@ "integrity": "sha1-CMBFaJIsJ3drii6BqV05M2LqC2U=" }, "convert-source-map": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.5.1.tgz", - "integrity": "sha1-uCeAl7m8IpNl3lxiz1/K7YtVmeU=" + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz", + "integrity": "sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A==", + "requires": { + "safe-buffer": "~5.1.1" + } }, "convert-string": { "version": "0.1.0", @@ -813,9 +809,9 @@ "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" }, "cookie-parser": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.3.tgz", - "integrity": "sha1-D+MfoZ0AC5X0qt8fU/3CuKIDuqU=", + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.4.tgz", + "integrity": "sha512-lo13tqF3JEtFO7FyA49CqbhaFkskRJ0u/UAiINgrIXeRCY41c88/zxtrECl8AKH3B0hj9q10+h3Kt8I7KlW4tw==", "requires": { "cookie": "0.3.1", "cookie-signature": "1.0.6" @@ -827,9 +823,9 @@ "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, "core-js": { - "version": "2.5.7", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.7.tgz", - "integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw==" + "version": "2.6.10", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.10.tgz", + "integrity": "sha512-I39t74+4t+zau64EN1fE5v2W31Adtc/REhzWN+gWRRXg6WH5qAsZm62DHpQ1+Yhe4047T55jvzz7MUqF/dBBlA==" }, "debug": { "version": "2.6.9", @@ -858,14 +854,13 @@ } }, "editorconfig": { - "version": "0.13.3", - "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.13.3.tgz", - "integrity": "sha512-WkjsUNVCu+ITKDj73QDvi0trvpdDWdkDyHybDGSXPfekLCqwmpD7CP7iPbvBgosNuLcI96XTDwNa75JyFl7tEQ==", - "requires": { - "bluebird": "^3.0.5", - "commander": "^2.9.0", - "lru-cache": "^3.2.0", - "semver": "^5.1.0", + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.15.3.tgz", + "integrity": "sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g==", + "requires": { + "commander": "^2.19.0", + "lru-cache": "^4.1.5", + "semver": "^5.6.0", "sigmund": "^1.0.1" } }, @@ -875,23 +870,15 @@ "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, "electron-to-chromium": { - "version": "1.3.50", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.50.tgz", - "integrity": "sha1-dDi3b5K0G5GfP73TUPvQdX2s3fc=" + "version": "1.3.285", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.285.tgz", + "integrity": "sha512-DYR9KW723sUbGK++DCmCmM95AbNXT4Q0tlCFMcYijFjayhuDqlGYR68OemlP8MJj0gjkwdeItIUfd0oLCgw+4A==" }, "encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" }, - "encoding": { - "version": "0.1.12", - "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", - "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", - "requires": { - "iconv-lite": "~0.4.13" - } - }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -903,9 +890,9 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "esutils": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=" + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==" }, "etag": { "version": "1.8.1", @@ -913,40 +900,52 @@ "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" }, "express": { - "version": "4.16.3", - "resolved": "https://registry.npmjs.org/express/-/express-4.16.3.tgz", - "integrity": "sha1-avilAjUNsyRuzEvs9rWjTSL37VM=", + "version": "4.17.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", + "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", "requires": { - "accepts": "~1.3.5", + "accepts": "~1.3.7", "array-flatten": "1.1.1", - "body-parser": "1.18.2", - "content-disposition": "0.5.2", + "body-parser": "1.19.0", + "content-disposition": "0.5.3", "content-type": "~1.0.4", - "cookie": "0.3.1", + "cookie": "0.4.0", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "~1.1.2", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "etag": "~1.8.1", - "finalhandler": "1.1.1", + "finalhandler": "~1.1.2", "fresh": "0.5.2", "merge-descriptors": "1.0.1", "methods": "~1.1.2", "on-finished": "~2.3.0", - "parseurl": "~1.3.2", + "parseurl": "~1.3.3", "path-to-regexp": "0.1.7", - "proxy-addr": "~2.0.3", - "qs": "6.5.1", - "range-parser": "~1.2.0", - "safe-buffer": "5.1.1", - "send": "0.16.2", - "serve-static": "1.13.2", - "setprototypeof": "1.1.0", - "statuses": "~1.4.0", - "type-is": "~1.6.16", + "proxy-addr": "~2.0.5", + "qs": "6.7.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.1.2", + "send": "0.17.1", + "serve-static": "1.14.1", + "setprototypeof": "1.1.1", + "statuses": "~1.5.0", + "type-is": "~1.6.18", "utils-merge": "1.0.1", "vary": "~1.1.2" + }, + "dependencies": { + "cookie": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz", + "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==" + }, + "parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" + } } }, "express-react-views": { @@ -962,39 +961,25 @@ "object-assign": "^4.1.1" } }, - "fbjs": { - "version": "0.8.17", - "resolved": "https://registry.npmjs.org/fbjs/-/fbjs-0.8.17.tgz", - "integrity": "sha1-xNWY6taUkRJlPWWIsBpc3Nn5D90=", - "requires": { - "core-js": "^1.0.0", - "isomorphic-fetch": "^2.1.1", - "loose-envify": "^1.0.0", - "object-assign": "^4.1.0", - "promise": "^7.1.1", - "setimmediate": "^1.0.5", - "ua-parser-js": "^0.7.18" - }, - "dependencies": { - "core-js": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz", - "integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=" - } - } - }, "finalhandler": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz", - "integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", + "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", "requires": { "debug": "2.6.9", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "on-finished": "~2.3.0", - "parseurl": "~1.3.2", - "statuses": "~1.4.0", + "parseurl": "~1.3.3", + "statuses": "~1.5.0", "unpipe": "~1.0.0" + }, + "dependencies": { + "parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" + } } }, "forwarded": { @@ -1007,11 +992,35 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "glob": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", + "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, "globals": { "version": "9.18.0", "resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz", "integrity": "sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==" }, + "graceful-fs": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.2.tgz", + "integrity": "sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q==", + "optional": true + }, "has-ansi": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", @@ -1030,20 +1039,33 @@ } }, "http-errors": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", - "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=", + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", + "integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==", "requires": { "depd": "~1.1.2", "inherits": "2.0.3", - "setprototypeof": "1.1.0", - "statuses": ">= 1.4.0 < 2" + "setprototypeof": "1.1.1", + "statuses": ">= 1.5.0 < 2", + "toidentifier": "1.0.0" } }, "iconv-lite": { - "version": "0.4.19", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", - "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } }, "inherits": { "version": "2.0.3", @@ -1064,9 +1086,9 @@ } }, "ipaddr.js": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.6.0.tgz", - "integrity": "sha1-4/o1e3c9phnybpXwSdBVxyeW+Gs=" + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz", + "integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA==" }, "is-finite": { "version": "1.0.2", @@ -1076,29 +1098,16 @@ "number-is-nan": "^1.0.0" } }, - "is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" - }, - "isomorphic-fetch": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", - "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", - "requires": { - "node-fetch": "^1.0.1", - "whatwg-fetch": ">=0.10.0" - } - }, "js-beautify": { - "version": "1.7.5", - "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.7.5.tgz", - "integrity": "sha512-9OhfAqGOrD7hoQBLJMTA+BKuKmoEtTJXzZ7WDF/9gvjtey1koVLuZqIY6c51aPDjbNdNtIXAkiWKVhziawE9Og==", + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.10.2.tgz", + "integrity": "sha512-ZtBYyNUYJIsBWERnQP0rPN9KjkrDfJcMjuVGcvXOUJrD1zmOGwhRwQ4msG+HJ+Ni/FA7+sRQEMYVzdTQDvnzvQ==", "requires": { - "config-chain": "~1.1.5", - "editorconfig": "^0.13.2", - "mkdirp": "~0.5.0", - "nopt": "~3.0.1" + "config-chain": "^1.1.12", + "editorconfig": "^0.15.3", + "glob": "^7.1.3", + "mkdirp": "~0.5.1", + "nopt": "~4.0.1" } }, "js-sha256": { @@ -1121,10 +1130,19 @@ "resolved": "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz", "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=" }, + "jsonfile": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-5.0.0.tgz", + "integrity": "sha512-NQRZ5CRo74MhMMC3/3r5g2k4fjodJ/wh8MxjFbCViWKFjxrnudWSY5vomh+23ZaXzAS7J3fBZIR2dV6WbmfM0w==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^0.1.2" + } + }, "lodash": { - "version": "4.17.10", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", - "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, "lodash.escaperegexp": { "version": "4.1.2", @@ -1132,19 +1150,20 @@ "integrity": "sha1-ZHYsSGGAglGKw99Mz11YhtriA0c=" }, "loose-envify": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz", - "integrity": "sha1-0aitM/qc4OcT1l/dCsi3SNR4yEg=", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", "requires": { - "js-tokens": "^3.0.0" + "js-tokens": "^3.0.0 || ^4.0.0" } }, "lru-cache": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-3.2.0.tgz", - "integrity": "sha1-cXibO39Tmb7IVl3aOKow0qCX7+4=", + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", + "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", "requires": { - "pseudomap": "^1.0.1" + "pseudomap": "^1.0.2", + "yallist": "^2.1.2" } }, "media-typer": { @@ -1174,21 +1193,21 @@ "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" }, "mime": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", - "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" }, "mime-db": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz", - "integrity": "sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==" + "version": "1.40.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz", + "integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA==" }, "mime-types": { - "version": "2.1.18", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz", - "integrity": "sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==", + "version": "2.1.24", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.24.tgz", + "integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==", "requires": { - "mime-db": "~1.33.0" + "mime-db": "1.40.0" } }, "minimatch": { @@ -1218,25 +1237,17 @@ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "negotiator": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", - "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" - }, - "node-fetch": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", - "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", - "requires": { - "encoding": "^0.1.11", - "is-stream": "^1.0.1" - } + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", + "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" }, "nopt": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz", - "integrity": "sha1-xkZdvwirzU2zWTF/eaxopkayj/k=", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", + "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", "requires": { - "abbrev": "1" + "abbrev": "1", + "osenv": "^0.1.4" } }, "number-is-nan": { @@ -1257,6 +1268,14 @@ "ee-first": "1.1.1" } }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, "os-homedir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", @@ -1267,10 +1286,19 @@ "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" }, + "osenv": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", + "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", + "requires": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" + } + }, "packet-reader": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-0.3.1.tgz", - "integrity": "sha1-zWLmCvjX/qinBexP+ZCHHEaHHyc=" + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz", + "integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==" }, "parseurl": { "version": "1.3.2", @@ -1288,15 +1316,15 @@ "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" }, "pg": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/pg/-/pg-7.5.0.tgz", - "integrity": "sha512-VFyAnp8xsMZp8nwZnMp7lmU5QcWDOZSI3IDNcWv6pblsiOXis5o7lD7/zzVK1Z1JTBiIDDGQAMbFMkiUzCL59A==", + "version": "7.12.1", + "resolved": "https://registry.npmjs.org/pg/-/pg-7.12.1.tgz", + "integrity": "sha512-l1UuyfEvoswYfcUe6k+JaxiN+5vkOgYcVSbSuw3FvdLqDbaoa2RJo1zfJKfPsSYPFVERd4GHvX3s2PjG1asSDA==", "requires": { - "buffer-writer": "1.0.1", - "packet-reader": "0.3.1", + "buffer-writer": "2.0.0", + "packet-reader": "1.0.0", "pg-connection-string": "0.1.3", - "pg-pool": "~2.0.3", - "pg-types": "~1.12.1", + "pg-pool": "^2.0.4", + "pg-types": "^2.1.0", "pgpass": "1.x", "semver": "4.3.2" }, @@ -1313,19 +1341,25 @@ "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-0.1.3.tgz", "integrity": "sha1-2hhHsglA5C7hSSvq9l1J2RskXfc=" }, + "pg-int8": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", + "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==" + }, "pg-pool": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.3.tgz", - "integrity": "sha1-wCIDLIlJ8xKk+R+2QJzgQHa+Mlc=" + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.7.tgz", + "integrity": "sha512-UiJyO5B9zZpu32GSlP0tXy8J2NsJ9EFGFfz5v6PSbdz/1hBLX1rNiiy5+mAm5iJJYwfCv4A0EBcQLGWwjbpzZw==" }, "pg-types": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-1.12.1.tgz", - "integrity": "sha1-1kCH45A7WP+q0nnnWVxSIIoUw9I=", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", + "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", "requires": { - "postgres-array": "~1.0.0", + "pg-int8": "1.0.1", + "postgres-array": "~2.0.0", "postgres-bytea": "~1.0.0", - "postgres-date": "~1.0.0", + "postgres-date": "~1.0.4", "postgres-interval": "^1.1.0" } }, @@ -1338,9 +1372,9 @@ } }, "postgres-array": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-1.0.3.tgz", - "integrity": "sha512-5wClXrAP0+78mcsNX3/ithQ5exKvCyK5lr5NEEEeGwwM6NJdQgzIJBVxLvRW+huFpX92F2QnZ5CcokH0VhK2qQ==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", + "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==" }, "postgres-bytea": { "version": "1.0.0", @@ -1348,14 +1382,14 @@ "integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU=" }, "postgres-date": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.3.tgz", - "integrity": "sha1-4tiXAu/bJY/52c7g/pG9BpdSV6g=" + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.4.tgz", + "integrity": "sha512-bESRvKVuTrjoBluEcpv2346+6kgB7UlnqWZsnbnCccTNq/pqfj1j6oBaN5+b/NrDXepYUT/HKadqv3iS9lJuVA==" }, "postgres-interval": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.1.2.tgz", - "integrity": "sha512-fC3xNHeTskCxL1dC8KOtxXt7YeFmlbTYtn7ul8MkVERuTmf7pI4DrkAxcw3kh1fQ9uz4wQmd03a1mRiXUZChfQ==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", + "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", "requires": { "xtend": "^4.0.0" } @@ -1365,21 +1399,14 @@ "resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz", "integrity": "sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg==" }, - "promise": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", - "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==", - "requires": { - "asap": "~2.0.3" - } - }, "prop-types": { - "version": "15.6.2", - "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz", - "integrity": "sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==", + "version": "15.7.2", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz", + "integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==", "requires": { - "loose-envify": "^1.3.1", - "object-assign": "^4.1.1" + "loose-envify": "^1.4.0", + "object-assign": "^4.1.1", + "react-is": "^16.8.1" } }, "proto-list": { @@ -1388,12 +1415,12 @@ "integrity": "sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=" }, "proxy-addr": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.3.tgz", - "integrity": "sha512-jQTChiCJteusULxjBp8+jftSQE5Obdl3k4cnmLA6WXtK6XFuWRnvVL7aCiBqaLPM8c4ph0S4tKna8XvmIwEnXQ==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz", + "integrity": "sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ==", "requires": { "forwarded": "~0.1.2", - "ipaddr.js": "1.6.0" + "ipaddr.js": "1.9.0" } }, "pseudomap": { @@ -1402,71 +1429,52 @@ "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" }, "qs": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", - "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", + "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" }, "range-parser": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", - "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" }, "raw-body": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", - "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz", + "integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==", "requires": { - "bytes": "3.0.0", - "http-errors": "1.6.2", - "iconv-lite": "0.4.19", + "bytes": "3.1.0", + "http-errors": "1.7.2", + "iconv-lite": "0.4.24", "unpipe": "1.0.0" - }, - "dependencies": { - "depd": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", - "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" - }, - "http-errors": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", - "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=", - "requires": { - "depd": "1.1.1", - "inherits": "2.0.3", - "setprototypeof": "1.0.3", - "statuses": ">= 1.3.1 < 2" - } - }, - "setprototypeof": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", - "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" - } } }, "react": { - "version": "16.3.2", - "resolved": "https://registry.npmjs.org/react/-/react-16.3.2.tgz", - "integrity": "sha512-o5GPdkhciQ3cEph6qgvYB7LTOHw/GB0qRI6ZFNugj49qJCFfgHwVNjZ5u+b7nif4vOeMIOuYj3CeYe2IBD74lg==", + "version": "16.10.2", + "resolved": "https://registry.npmjs.org/react/-/react-16.10.2.tgz", + "integrity": "sha512-MFVIq0DpIhrHFyqLU0S3+4dIcBhhOvBE8bJ/5kHPVOVaGdo0KuiQzpcjCPsf585WvhypqtrMILyoE2th6dT+Lw==", "requires": { - "fbjs": "^0.8.16", "loose-envify": "^1.1.0", "object-assign": "^4.1.1", - "prop-types": "^15.6.0" + "prop-types": "^15.6.2" } }, "react-dom": { - "version": "16.3.2", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.3.2.tgz", - "integrity": "sha512-MMPko3zYncNrz/7gG17wJWUREZDvskZHXOwbttzl0F0L3wDmToyuETuo/r8Y5yvDejwYcRyWI1lvVBjLJWFwKA==", + "version": "16.10.2", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.10.2.tgz", + "integrity": "sha512-kWGDcH3ItJK4+6Pl9DZB16BXYAZyrYQItU4OMy0jAkv5aNqc+mAKb4TpFtAteI6TJZu+9ZlNhaeNQSVQDHJzkw==", "requires": { - "fbjs": "^0.8.16", "loose-envify": "^1.1.0", "object-assign": "^4.1.1", - "prop-types": "^15.6.0" + "prop-types": "^15.6.2", + "scheduler": "^0.16.2" } }, + "react-is": { + "version": "16.10.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.10.2.tgz", + "integrity": "sha512-INBT1QEgtcCCgvccr5/86CfD71fw9EPmDxgiJX4I2Ddr6ZsV6iFXsuby+qWJPtmNuMY0zByTsG4468P7nHuNWA==" + }, "regenerate": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", @@ -1519,19 +1527,33 @@ } }, "safe-buffer": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "scheduler": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.16.2.tgz", + "integrity": "sha512-BqYVWqwz6s1wZMhjFvLfVR5WXP7ZY32M/wYPo04CcuPM7XZEbV2TBNW7Z0UkguPTl0dWMA59VbNXxK6q+pHItg==", + "requires": { + "loose-envify": "^1.1.0", + "object-assign": "^4.1.1" + } }, "semver": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" }, "send": { - "version": "0.16.2", - "resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz", - "integrity": "sha512-E64YFPUssFHEFBvpbbjr44NCLtI1AohxQ8ZSiJjQLskAdKuriYEP6VyGEsRDH8ScozGpkaX1BGvhanqCwkcEZw==", + "version": "0.17.1", + "resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz", + "integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==", "requires": { "debug": "2.6.9", "depd": "~1.1.2", @@ -1540,34 +1562,43 @@ "escape-html": "~1.0.3", "etag": "~1.8.1", "fresh": "0.5.2", - "http-errors": "~1.6.2", - "mime": "1.4.1", - "ms": "2.0.0", + "http-errors": "~1.7.2", + "mime": "1.6.0", + "ms": "2.1.1", "on-finished": "~2.3.0", - "range-parser": "~1.2.0", - "statuses": "~1.4.0" + "range-parser": "~1.2.1", + "statuses": "~1.5.0" + }, + "dependencies": { + "ms": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" + } } }, "serve-static": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz", - "integrity": "sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw==", + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz", + "integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==", "requires": { "encodeurl": "~1.0.2", "escape-html": "~1.0.3", - "parseurl": "~1.3.2", - "send": "0.16.2" + "parseurl": "~1.3.3", + "send": "0.17.1" + }, + "dependencies": { + "parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" + } } }, - "setimmediate": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" - }, "setprototypeof": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", - "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", + "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" }, "sha256": { "version": "0.2.0", @@ -1610,9 +1641,9 @@ } }, "statuses": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", - "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", + "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" }, "strip-ansi": { "version": "3.0.1", @@ -1637,24 +1668,29 @@ "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz", "integrity": "sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=" }, + "toidentifier": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", + "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" + }, "trim-right": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz", "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=" }, "type-is": { - "version": "1.6.16", - "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz", - "integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==", + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", "requires": { "media-typer": "0.3.0", - "mime-types": "~2.1.18" + "mime-types": "~2.1.24" } }, - "ua-parser-js": { - "version": "0.7.18", - "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.18.tgz", - "integrity": "sha512-LtzwHlVHwFGTptfNSgezHp7WUlwiqb0gA9AALRbKaERfxwJoiX0A73QbTToxteIAuIaFshhgIZfqK8s7clqgnA==" + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" }, "unpipe": { "version": "1.0.0", @@ -1671,15 +1707,20 @@ "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" }, - "whatwg-fetch": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", - "integrity": "sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==" + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "xtend": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" + }, + "yallist": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", + "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" } } } diff --git a/package.json b/package.json index 5f4651b..3398391 100644 --- a/package.json +++ b/package.json @@ -10,14 +10,25 @@ "start": "node index.js" }, "dependencies": { - "cookie-parser": "^1.4.3", - "express": "^4.16.3", + "cookie-parser": "^1.4.4", + "express": "^4.17.1", "express-react-views": "^0.10.5", "js-sha256": "^0.9.0", + "jsonfile": "^5.0.0", "method-override": "^2.3.10", - "pg": "^7.4.3", - "react": "^16.3.2", - "react-dom": "^16.3.2", + "pg": "^7.12.1", + "react": "^16.10.2", + "react-dom": "^16.10.2", "sha256": "^0.2.0" - } + }, + "description": "Let's make a cool new app called TWEEDR!! Not Twitter, geez...", + "repository": { + "type": "git", + "url": "git+https://github.com/kellylimmm/tweedr.git" + }, + "author": "", + "bugs": { + "url": "https://github.com/kellylimmm/tweedr/issues" + }, + "homepage": "https://github.com/kellylimmm/tweedr#readme" } diff --git a/seed.sql b/seed.sql new file mode 100644 index 0000000..c321f5b --- /dev/null +++ b/seed.sql @@ -0,0 +1,26 @@ +INSERT INTO users (name, username, password) VALUES ('Babara', 'babas','pwhottiebabe'); +INSERT INTO users (name, username, password) VALUES ('Titus', 'coolguy','pwtomato'); +INSERT INTO users (name, username, password) VALUES ('Terry', 'supersonic', 'pwsonic'); +INSERT INTO users (name, username, password) VALUES ('Jeremy', 'silentfame', 'pwpassword'); +INSERT INTO users (name, username, password) VALUES ('Ignatius', 'iggy', 'pwiggy'); +INSERT INTO users (name, username, password) VALUES ('Jason', 'madskills','pwjassie'); +INSERT INTO users (name, username, password) VALUES ('Benjamin', 'bennie','pwbarker'); +INSERT INTO users (name, username, password) VALUES ('Rahman', 'hotwheels','pwrahman'); +INSERT INTO users (name, username, password) VALUES ('Jonathan', 'jonnie','pwjona'); +INSERT INTO users (name, username, password) VALUES ('Sonia', 'thesonia', 'pwsonia'); + +INSERT INTO tweets (content, user_id) VALUES ('My first tweet!', 1); +INSERT INTO tweets (content, user_id) VALUES ('What a hot day!', 2); +INSERT INTO tweets (content, user_id) VALUES ('First time cooking', 2); +INSERT INTO tweets (content, user_id) VALUES ('Lol what a day', 3); +INSERT INTO tweets (content, user_id) VALUES ('Really want my holiday', 4); +INSERT INTO tweets (content, user_id) VALUES ('Kindness all over', 5); +INSERT INTO tweets (content, user_id) VALUES ('Be gracious and nice', 5); +INSERT INTO tweets (content, user_id) VALUES ('I cannot wait for this sunday!', 5); +INSERT INTO tweets (content, user_id) VALUES ('This is exciting', 6); +INSERT INTO tweets (content, user_id) VALUES ('first day at work', 6); +INSERT INTO tweets (content, user_id) VALUES ('happiness and gratefulness', 7); +INSERT INTO tweets (content, user_id) VALUES ('why is everyone so nice', 8); +INSERT INTO tweets (content, user_id) VALUES ('first time cycling', 8); +INSERT INTO tweets (content, user_id) VALUES ('nice day at a park', 9); +INSERT INTO tweets (content, user_id) VALUES ('picnic at botanic gardens', 10); \ No newline at end of file diff --git a/tables.sql b/tables.sql new file mode 100644 index 0000000..e4c5137 --- /dev/null +++ b/tables.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS users ( + id SERIAL PRIMARY KEY, + name TEXT, + username TEXT, + password TEXT +); + +CREATE TABLE IF NOT EXISTS tweets ( + id SERIAL PRIMARY KEY, + content TEXT, + user_id INTEGER +); \ No newline at end of file diff --git a/views/login.jsx b/views/login.jsx new file mode 100644 index 0000000..7bb78d1 --- /dev/null +++ b/views/login.jsx @@ -0,0 +1,28 @@ +var React = require('react'); + +class Login extends React.Component { + render() { + return ( + + +

LOGINNNNNN

+
+

+ Username
+ +

+

+ Password
+ +

+

+ +

+
+ + + ); + } +} + +module.exports = Login; \ No newline at end of file diff --git a/views/user/NewUser.jsx b/views/user/NewUser.jsx index 4faac60..413cfb2 100644 --- a/views/user/NewUser.jsx +++ b/views/user/NewUser.jsx @@ -6,12 +6,13 @@ class NewUser extends React.Component { +

Welcome to Tweedr. PLEASE REGISTER!

- name + Username
- password: + Password:
@@ -21,4 +22,4 @@ class NewUser extends React.Component { } } -module.exports = NewUser; +module.exports = NewUser; \ No newline at end of file From 2cb9fd2b0908f2ec17fe3b26977438966ea1949f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Ckellylimmm=E2=80=9D?= <“kellylim.06@gmail.com”> Date: Sat, 19 Oct 2019 15:53:18 +0800 Subject: [PATCH 2/5] MVP but left ability to tweet --- index.js | 36 ++++++++++++++++++++++++++++++++---- views/home.jsx | 23 +++++++++++++++++++++++ views/user/profile.jsx | 20 ++++++++++++++++++++ 3 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 views/home.jsx create mode 100644 views/user/profile.jsx diff --git a/index.js b/index.js index 349208f..cdc7cff 100644 --- a/index.js +++ b/index.js @@ -56,8 +56,19 @@ app.use(cookieParser()); // Root GET request (it doesn't belong in any controller file) app.get('/', (request, response) => { - response.send('Welcome To Tweedr.'); + const queryString = `SELECT tweets.*, users.username FROM tweets INNER JOIN users ON tweets.user_id = users.id`; + + pool.query(queryString, (err, result) => { + let tweets = {}; + tweets.list=[]; + for(let i = 0; i < result.rows.length; i++){ + tweets.list.push(result.rows[i]); + } + response.render('Home', tweets); + }); }); +// response.send('Welcome To Tweedr.'); +// }); app.get('/users/new', (request, response) => { response.render('user/newuser'); @@ -95,8 +106,8 @@ app.post('/users', (request, response) => { } else { console.log('query result:', result); - - response.send( result.rows ); + response.redirect('/login'); + // response.send( result.rows ); } }); }); @@ -136,7 +147,7 @@ if (result.rows.length > 0) { response.cookie('user_id', user_id); response.cookie('hasLoggedIn', hashedCookie); - response.send('LOGGING IN.....'); + response.redirect('/'); } else { response.status(403).send('wrong password'); } @@ -170,6 +181,23 @@ if (request.cookies['hasLoggedIn'] === hashedValue) { }); +// ======== User Profile ======== + +// app.get('/user/profile', (request, response) => { +// let user_id = request.cookies['user_id']; + +// const queryString = 'SELECT users.username, tweets.content FROM tweets INNER JOIN users ON users.id=tweets'; + +// // execute query +// pool.query(queryString, (err, result) => { +// console.log(result.rows); +// response.render('/user/profile', {tweets: result.rows}); +// }); +// }); + + + + /** * =================================== * Listen to requests on port 3000 diff --git a/views/home.jsx b/views/home.jsx new file mode 100644 index 0000000..de3dd4f --- /dev/null +++ b/views/home.jsx @@ -0,0 +1,23 @@ +var React = require("react"); + +class Home extends React.Component { + render() { + + let tweets = this.props.list.map( tweets => { + + return ( +

+ {tweets.user_id} has tweeted:"{tweets.content}". +

+ ); + }); + + return ( +
+ {tweets} +
+ ); + } +} + +module.exports = Home; \ No newline at end of file diff --git a/views/user/profile.jsx b/views/user/profile.jsx new file mode 100644 index 0000000..ea833fc --- /dev/null +++ b/views/user/profile.jsx @@ -0,0 +1,20 @@ +var React = require('react'); + +class Profile extends React.Component { + render() { + return ( + + + +
+
+ Tweets
+
+
+ + + ); + } +} + +module.exports = Profile; \ No newline at end of file From eb68159fe9f537055aa9bbe69e84b0970f90ad72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Ckellylimmm=E2=80=9D?= <“kellylim.06@gmail.com”> Date: Sat, 19 Oct 2019 17:56:58 +0800 Subject: [PATCH 3/5] Able to add tweet. Displaying tweet not done yet --- index.js | 52 +++++++++++++++++++++++++++++++++++-------------- views/tweet.jsx | 20 +++++++++++++++++++ 2 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 views/tweet.jsx diff --git a/index.js b/index.js index cdc7cff..d34b77f 100644 --- a/index.js +++ b/index.js @@ -86,18 +86,7 @@ app.post('/users', (request, response) => { hashedPassword, ]; - // execute query - // pool.query(queryString, values, (err, result) => { - - // if (err) { - // console.error('query error: ', err.stack); - // response.send('query error'); - // } else { - // console.log('query result: ', result); - // //response.redirect('/'); - // response.send('user created'); - // console.log(result.rows, "JAJAJAJA"); - // } + // execute query pool.query(queryString, values, (err,result) =>{ if (err) { @@ -154,9 +143,9 @@ if (result.rows.length > 0) { } -else { - response.status(403).send('NO USERNAME!'); -} + else { + response.status(403).send('NO USERNAME!'); + } } }); @@ -181,6 +170,39 @@ if (request.cookies['hasLoggedIn'] === hashedValue) { }); +// ========== Tweeting ============= + +app.get('/tweets/new', (request, response) => { + // let text = "SELECT * FROM tweets"; + + // pool.query(text, (err, result) => { + // response.render("tweet", {tweets: result.rows}); + // }) + response.render('tweet'); +}); + +app.post('/tweets/new', (request, response) => { + const newTweet = 'INSERT INTO tweets (content) VALUES ($1)'; + console.log(request.body); + let values = [request.body.tweets]; + console.log(values); + + pool.query(newTweet, values, (err, result) => { + + let tweets =[]; + + for(let i = 0; i < result.rows.length; i++){ + tweets.push(result.rows[i]); + } + console.log(result.rows); + response.redirect('/'); + }); +}); + + + + + // ======== User Profile ======== // app.get('/user/profile', (request, response) => { diff --git a/views/tweet.jsx b/views/tweet.jsx new file mode 100644 index 0000000..340581a --- /dev/null +++ b/views/tweet.jsx @@ -0,0 +1,20 @@ +var React = require ('react'); + +class Tweet extends React.Component { + render () { + + // const tweets = this.props.tweets.map; + return( +
+

Tweet!

+
+

Your message here: +

+ +
+
+ ) + } +} + +module.exports = Tweet; \ No newline at end of file From 256e75fbcfe65ece7eb051b0cc8a2a457259def0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Ckellylimmm=E2=80=9D?= <“kellylim.06@gmail.com”> Date: Sun, 20 Oct 2019 20:46:44 +0800 Subject: [PATCH 4/5] A bit of MVC --- controllers/users.js | 0 db.js | 57 ++++++++++++++++++++++++++++++++++++ models/users.js | 69 ++++++++++++++++++++++++++++++++++++++++++++ routes.js | 16 ++++++++++ 4 files changed, 142 insertions(+) create mode 100644 controllers/users.js create mode 100644 db.js create mode 100644 models/users.js create mode 100644 routes.js diff --git a/controllers/users.js b/controllers/users.js new file mode 100644 index 0000000..e69de29 diff --git a/db.js b/db.js new file mode 100644 index 0000000..33f7059 --- /dev/null +++ b/db.js @@ -0,0 +1,57 @@ +const pg = require('pg'); +const url = require('url'); + + +var configs; + +if( process.env.DATABASE_URL ){ + + const params = url.parse(process.env.DATABASE_URL); + const auth = params.auth.split(':'); + + configs = { + user: auth[0], + password: auth[1], + host: params.hostname, + port: params.port, + database: params.pathname.split('/')[1], + ssl: true + }; + +}else{ + configs = { + user: 'kellylim', + host: '127.0.0.1', + database: 'tweedr', + port: 5432 + }; +} + +const pool = new pg.Pool(configs); + +pool.on('error', function (err) { + console.log('idle client error', err.message, err.stack); +}); + +//Require Model Files + +const allUsersModelsFunction = require('./models/users'); + +const usersModelsObject = allUsersModelsFunction( pool ); + +module.exports = { + //make queries directly from here + queryInterface: (text, params, callback) => { + return pool.query(text, params, callback); + }, + + // get a reference to end the connection pool at server end + pool:pool, + + /* + * ADD APP MODELS HERE + */ + + // users: userModelsObject, + users: usersModelsObject +}; \ No newline at end of file diff --git a/models/users.js b/models/users.js new file mode 100644 index 0000000..a4b3367 --- /dev/null +++ b/models/users.js @@ -0,0 +1,69 @@ +module.exports = (dbPoolInstance) => { + +let newUsers = (callback) => { + let hashedPassword = sha256(request.body.password + SALT); + const queryString = 'INSERT INTO users (username, password) VALUES ($1, $2) RETURNING *'; + + const values = [ + request.body.username, + hashedPassword, + ]; + + dbPoolInstance.query(query, (err, result) => { + if (err) { + callback(err,null); + } + }) +} + + +let getLogIn = (callback) => { + + let requestUsername = request.body.username; + let requestPassword = request.body.password; + + const queryString = "SELECT * FROM users WHERE username= '"+requestUsername+"'"; + + dbPoolInstance.query(query, (err, result) => { + if( err ){ + + // invoke callback function with results after query has executed + callback(err, null); + + }else{ + + // invoke callback function with results after query has executed + + if( result.rows.length > 0 ){ + callback('query result: ', result.rows); + + + }else{ + callback(null, null); + + } + } + }); + + }; + + + + let newTweets = (callback) => { + const newTweet = 'INSERT INTO tweets (content) VALUES ($1)'; + let values = [request.body.tweets]; + let tweets = []; + + dbPoolInstance.query(newTweet, values, (err, result) => { + for (let i = 0; i < result.rows.length; i++){ + tweets.push(result.rows[i]); + } + }) + } + + return { + getLogIn: getLogIn, + newTweets: newTweets, + newUsers: newUsers + }; +} \ No newline at end of file diff --git a/routes.js b/routes.js new file mode 100644 index 0000000..57425f3 --- /dev/null +++ b/routes.js @@ -0,0 +1,16 @@ +module.exports = (app, db) => { + +const users = require('./controllers/tweedr')(db); + +app.get('/', users.home); +app.get('/users/new', users.newUser); +app.post('/users', users.users); +app.get('/login', users.signIn); +app.post('/login', users.postTweets); +app.get('/special', tweets.cookie); +app.get('/tweets/new', tweets.newTweets); +app.post('/tweets/new', tweets.postNewTweets); + + + +} \ No newline at end of file From a89f80fba8ca0bedf13ebb3d3037bf515da43ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Ckellylimmm=E2=80=9D?= <“kellylim.06@gmail.com”> Date: Mon, 21 Oct 2019 00:31:16 +0800 Subject: [PATCH 5/5] Update --- controllers/users.js | 142 ++++++++++++++++++ index.js | 344 ++++++++++++++++++++++++------------------- 2 files changed, 335 insertions(+), 151 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index e69de29..e349078 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -0,0 +1,142 @@ +var sha256 = require('js-sha256'); +var SALT = "tweedr"; + + +module.exports = (db) => { + + const registerControllerCallback(request,response) => { + + let hashedPassword = sha256(request.body.password + SALT); + + const queryString = 'INSERT INTO users (username, password) VALUES ($1, $2) RETURNING *'; + + const values = [ + request.body.username, + hashedPassword, + ]; + + db.tweedr.getUsers(queryString, values, (err,result) =>{ + + + if (err) { + console.error('query error:', err.stack); + response.send( 'query error' ); + } else { + console.log('query result:', result); + + response.redirect('/login'); + + } + + }); + + + const indexControllerCallback(request,response) => { + + db.tweedr.getAll(queryString, (err, result) => { + let tweets = {}; + tweets.list=[]; + for(let i = 0; i < result.rows.length; i++){ + tweets.list.push(result.rows[i]); + } + response.render('Home', tweets); + }); + + } + + const loginControllerCallback(request,response) =>{ + + let requestUsername = request.body.username; + let requestPassword = request.body.password; + + const queryString = "SELECT * FROM users WHERE username= '"+requestUsername+"'"; + + db.tweedr.getUsers(queryString, (err, result) => { + + if (err) { + console.error('query error: ', err.stack); + response.send('query error'); + } else { + console.log('query result: ', result.rows); + + + if (result.rows.length > 0) { + + let hashedRequestPassword = sha256(requestPassword + SALT); + + if (hashedRequestPassword === result.rows[0].password) { + let user_id = result.rows[0].id + let hashedCookie = sha256(SALT+ user_id); + + + response.cookie('user_id', user_id); + response.cookie('hasLoggedIn', hashedCookie); + + response.redirect('/'); + } else { + response.status(403).send('wrong password'); + } + + } + + else { + response.status(403).send('NO USERNAME!'); + } + } + + }); + } + + const tweetControllerCallback(request,response) => { + response.render('tweet'); + } + + const newTweetControllerCallback(request,response) => { + + const newTweet = 'INSERT INTO tweets (content) VALUES ($1)'; + console.log(request.body); + let values = [request.body.tweets]; + console.log(values); + + db.tweedr.tweedr(newTweet, values, (err, result) => { + + let tweets =[]; + + for(let i = 0; i < result.rows.length; i++){ + tweets.push(result.rows[i]); + } + console.log(result.rows); + response.redirect('/'); + }); + + } + + const cookieControllerCallback(request,response) =>{ + let user_id = request.cookies['user_id']; + let hashedValue = sha256(SALT + user_id); + + + if (request.cookies['hasLoggedIn'] === hashedValue) { + response.send("LOGGED IN"); + } else { + response.redirect('/login'); + } + + + } + + + +} + +return{ + register : registerControllerCallback, + index : indexControllerCallback, + login : loginControllerCallback, + tweet : tweetControllerCallback, + newTweet : newTweetControllerCallback, + cookie : cookieControllerCallback +} + + +} \ No newline at end of file diff --git a/index.js b/index.js index d34b77f..e81b5e1 100644 --- a/index.js +++ b/index.js @@ -2,31 +2,6 @@ const express = require('express'); const methodOverride = require('method-override'); const cookieParser = require('cookie-parser'); -const pg = require('pg'); - -var sha256 = require('js-sha256'); - -var SALT = "tweedr"; - -/** - * =================================== - * Configurations and set up - * =================================== - */ - -const configs = { - user: 'kellylim', - host: '127.0.0.1', - database: 'tweedr', - port: 5432, -}; - -const pool = new pg.Pool(configs); - -pool.on('error', function (err) { - console.log('idle client error', err.message, err.stack); -}); - // Init express app const app = express(); @@ -45,6 +20,73 @@ app.engine('jsx', reactEngine); // Set the configuration to tell express to use cookie parser app.use(cookieParser()); +// const pg = require('pg'); + +var sha256 = require('js-sha256'); +var SALT = "tweedr"; + +// db contains *ALL* of our models +const allModels = require('./db'); +// get the thing that contains all the routes +const setRoutesFunction = require('./routes'); +// call it and pass in the "app" so that we can set routes on it (also models) +setRoutesFunction(app, allModels); + +const PORT = process.env.PORT || 3000; + +const server = app.listen(PORT, () => console.log('~~~ Tuning in to the waves of port '+PORT+' ~~~')); + +let onClose = function(){ + + server.close(() => { + console.log('Process terminated') + allModels.pool.end( () => console.log('Shut down db connection pool')); + }) +}; + +process.on('SIGTERM', onClose); +process.on('SIGINT', onClose); + + +// ============================================================= + +/** + * =================================== + * Configurations and set up + * =================================== + */ + +// const configs = { +// user: 'kellylim', +// host: '127.0.0.1', +// database: 'tweedr', +// port: 5432, +// }; + +// const pool = new pg.Pool(configs); + +// pool.on('error', function (err) { +// console.log('idle client error', err.message, err.stack); +// }); + +// // Init express app +// const app = express(); + +// // Set up middleware +// app.use(methodOverride('_method')); +// app.use(cookieParser()); +// app.use(express.urlencoded({ +// extended: true +// })); + +// // Set react-views to be the default view engine +// const reactEngine = require('express-react-views').createEngine(); +// app.set('views', __dirname + '/views'); +// app.set('view engine', 'jsx'); +// app.engine('jsx', reactEngine); + +// // Set the configuration to tell express to use cookie parser +// app.use(cookieParser()); /** * =================================== @@ -55,186 +97,186 @@ app.use(cookieParser()); // ============ Register ========= // Root GET request (it doesn't belong in any controller file) -app.get('/', (request, response) => { - const queryString = `SELECT tweets.*, users.username FROM tweets INNER JOIN users ON tweets.user_id = users.id`; - - pool.query(queryString, (err, result) => { - let tweets = {}; - tweets.list=[]; - for(let i = 0; i < result.rows.length; i++){ - tweets.list.push(result.rows[i]); - } - response.render('Home', tweets); - }); -}); -// response.send('Welcome To Tweedr.'); +// app.get('/', (request, response) => { +// const queryString = `SELECT tweets.*, users.username FROM tweets INNER JOIN users ON tweets.user_id = users.id`; + +// pool.query(queryString, (err, result) => { +// let tweets = {}; +// tweets.list=[]; +// for(let i = 0; i < result.rows.length; i++){ +// tweets.list.push(result.rows[i]); +// } +// response.render('Home', tweets); +// }); // }); +// // response.send('Welcome To Tweedr.'); +// // }); -app.get('/users/new', (request, response) => { - response.render('user/newuser'); -}); +// app.get('/users/new', (request, response) => { +// response.render('user/newuser'); +// }); -app.post('/users', (request, response) => { - console.log(request.body); +// app.post('/users', (request, response) => { +// console.log(request.body); - let hashedPassword = sha256(request.body.password + SALT); +// let hashedPassword = sha256(request.body.password + SALT); - const queryString = 'INSERT INTO users (username, password) VALUES ($1, $2) RETURNING *'; +// const queryString = 'INSERT INTO users (username, password) VALUES ($1, $2) RETURNING *'; - const values = [ - request.body.username, - hashedPassword, - ]; +// const values = [ +// request.body.username, +// hashedPassword, +// ]; - // execute query - pool.query(queryString, values, (err,result) =>{ +// // execute query +// pool.query(queryString, values, (err,result) =>{ - if (err) { - console.error('query error:', err.stack); - response.send( 'query error' ); - } else { - console.log('query result:', result); +// if (err) { +// console.error('query error:', err.stack); +// response.send( 'query error' ); +// } else { +// console.log('query result:', result); - response.redirect('/login'); - // response.send( result.rows ); - } - }); -}); +// response.redirect('/login'); +// // response.send( result.rows ); +// } +// }); +// }); -//========== Login ============= +// //========== Login ============= -app.get('/login', (request, response) => { - response.render('login'); -}) +// app.get('/login', (request, response) => { +// response.render('login'); +// }) -app.post('/login', (request, response) => { - let requestUsername = request.body.username; - let requestPassword = request.body.password; +// app.post('/login', (request, response) => { +// let requestUsername = request.body.username; +// let requestPassword = request.body.password; - const queryString = "SELECT * FROM users WHERE username= '"+requestUsername+"'"; - console.log("db query", queryString); +// const queryString = "SELECT * FROM users WHERE username= '"+requestUsername+"'"; +// console.log("db query", queryString); - pool.query(queryString, (err, result) => { +// pool.query(queryString, (err, result) => { - if (err) { - console.error('query error: ', err.stack); - response.send('query error'); - } else { - console.log('query result: ', result.rows); +// if (err) { +// console.error('query error: ', err.stack); +// response.send('query error'); +// } else { +// console.log('query result: ', result.rows); -if (result.rows.length > 0) { +// if (result.rows.length > 0) { - let hashedRequestPassword = sha256(requestPassword + SALT); - console.log("hashed request password : " + hashedRequestPassword); +// let hashedRequestPassword = sha256(requestPassword + SALT); +// console.log("hashed request password : " + hashedRequestPassword); - if (hashedRequestPassword === result.rows[0].password) { - let user_id = result.rows[0].id - let hashedCookie = sha256(SALT+ user_id); +// if (hashedRequestPassword === result.rows[0].password) { +// let user_id = result.rows[0].id +// let hashedCookie = sha256(SALT+ user_id); - response.cookie('user_id', user_id); - response.cookie('hasLoggedIn', hashedCookie); +// response.cookie('user_id', user_id); +// response.cookie('hasLoggedIn', hashedCookie); - response.redirect('/'); - } else { - response.status(403).send('wrong password'); - } +// response.redirect('/'); +// } else { +// response.status(403).send('wrong password'); +// } -} +// } - else { - response.status(403).send('NO USERNAME!'); - } - } +// else { +// response.status(403).send('NO USERNAME!'); +// } +// } - }); +// }); -}); +// }); -//=========== Cookies ======= +// //=========== Cookies ======= -app.get('/special', (request,response) => { +// app.get('/special', (request,response) => { - let user_id = request.cookies['user_id']; - let hashedValue = sha256(SALT + user_id); +// let user_id = request.cookies['user_id']; +// let hashedValue = sha256(SALT + user_id); -if (request.cookies['hasLoggedIn'] === hashedValue) { - response.send("LOGGED IN"); -} else { - response.redirect('/login'); -} +// if (request.cookies['hasLoggedIn'] === hashedValue) { +// response.send("LOGGED IN"); +// } else { +// response.redirect('/login'); +// } -}); +// }); -// ========== Tweeting ============= +// // ========== Tweeting ============= -app.get('/tweets/new', (request, response) => { - // let text = "SELECT * FROM tweets"; +// app.get('/tweets/new', (request, response) => { +// // let text = "SELECT * FROM tweets"; - // pool.query(text, (err, result) => { - // response.render("tweet", {tweets: result.rows}); - // }) - response.render('tweet'); -}); +// // pool.query(text, (err, result) => { +// // response.render("tweet", {tweets: result.rows}); +// // }) +// response.render('tweet'); +// }); -app.post('/tweets/new', (request, response) => { - const newTweet = 'INSERT INTO tweets (content) VALUES ($1)'; - console.log(request.body); - let values = [request.body.tweets]; - console.log(values); +// app.post('/tweets/new', (request, response) => { +// const newTweet = 'INSERT INTO tweets (content) VALUES ($1)'; +// console.log(request.body); +// let values = [request.body.tweets]; +// console.log(values); - pool.query(newTweet, values, (err, result) => { +// pool.query(newTweet, values, (err, result) => { - let tweets =[]; +// let tweets =[]; - for(let i = 0; i < result.rows.length; i++){ - tweets.push(result.rows[i]); - } - console.log(result.rows); - response.redirect('/'); - }); -}); +// for(let i = 0; i < result.rows.length; i++){ +// tweets.push(result.rows[i]); +// } +// console.log(result.rows); +// response.redirect('/'); +// }); +// }); -// ======== User Profile ======== +// // ======== User Profile ======== -// app.get('/user/profile', (request, response) => { -// let user_id = request.cookies['user_id']; +// // app.get('/user/profile', (request, response) => { +// // let user_id = request.cookies['user_id']; -// const queryString = 'SELECT users.username, tweets.content FROM tweets INNER JOIN users ON users.id=tweets'; +// // const queryString = 'SELECT users.username, tweets.content FROM tweets INNER JOIN users ON users.id=tweets'; -// // execute query -// pool.query(queryString, (err, result) => { -// console.log(result.rows); -// response.render('/user/profile', {tweets: result.rows}); -// }); -// }); +// // // execute query +// // pool.query(queryString, (err, result) => { +// // console.log(result.rows); +// // response.render('/user/profile', {tweets: result.rows}); +// // }); +// // }); -/** - * =================================== - * Listen to requests on port 3000 - * =================================== - */ +// /** +// * =================================== +// * Listen to requests on port 3000 +// * =================================== +// */ -const server = app.listen(3000, () => console.log('~~~ Tuning in to the waves of port 3000 ~~~')); +// const server = app.listen(3000, () => console.log('~~~ Tuning in to the waves of port 3000 ~~~')); -let onClose = function(){ +// let onClose = function(){ - server.close(() => { - console.log('Process terminated') - pool.end( () => console.log('Shut down db connection pool')); - }) -}; +// server.close(() => { +// console.log('Process terminated') +// pool.end( () => console.log('Shut down db connection pool')); +// }) +// }; -process.on('SIGTERM', onClose); -process.on('SIGINT', onClose); \ No newline at end of file +// process.on('SIGTERM', onClose); +// process.on('SIGINT', onClose); \ No newline at end of file