From 0d5061f400a5be88a93cc06c49dfb5bdd7bd986d Mon Sep 17 00:00:00 2001 From: John Ahn Date: Sun, 3 May 2020 22:08:07 +0900 Subject: [PATCH] Changed --- .../views/RegisterPage/RegisterPage.js | 24 ---- client/src/hoc/auth.js | 4 +- client/src/index.css | 4 + package-lock.json | 135 ++++++++++++++++++ package.json | 17 +-- server/index.js | 14 +- server/models/user.js | 44 +++--- server/routes/users.js | 22 +-- 8 files changed, 192 insertions(+), 72 deletions(-) diff --git a/client/src/components/views/RegisterPage/RegisterPage.js b/client/src/components/views/RegisterPage/RegisterPage.js index 55aa830..cad19d9 100644 --- a/client/src/components/views/RegisterPage/RegisterPage.js +++ b/client/src/components/views/RegisterPage/RegisterPage.js @@ -39,18 +39,13 @@ function RegisterPage(props) { { setTimeout(() => { let dataToSubmit = { - account: values.account, email: values.email, password: values.password, name: values.name, // lastname: values.lastname, image: `uploads/images/no-user.svg`, - company: parseInt(values.company, 10) }; dispatch(registerUser(dataToSubmit)).then(response => { @@ -103,23 +96,6 @@ function RegisterPage(props) {
- - - {errors.account && touched.account && ( -
{errors.account}
- )} -
- = 2.1.2 < 3" } }, + "ienoopen": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/ienoopen/-/ienoopen-1.1.0.tgz", + "integrity": "sha512-MFs36e/ca6ohEKtinTJ5VvAJ6oDRAYFdYXweUnGY9L9vcoqFOU4n2ZhmJ0C4z/cwGZ3YIQRSB3XZ1+ghZkY5NQ==" + }, "ignore-by-default": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", @@ -4206,6 +4326,11 @@ "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, + "nocache": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/nocache/-/nocache-2.1.0.tgz", + "integrity": "sha512-0L9FvHG3nfnnmaEQPjT9xhfN4ISk0A8/2j4M37Np4mcDesJjHgEUfgPhdCyZuFI954tjokaIj/A3NdpFNdEh4Q==" + }, "node-fetch": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", @@ -5476,6 +5601,11 @@ } } }, + "referrer-policy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/referrer-policy/-/referrer-policy-1.2.0.tgz", + "integrity": "sha512-LgQJIuS6nAy1Jd88DCQRemyE3mS+ispwlqMk3b0yjZ257fI1v9c+/p6SD5gP5FGyXUIgrNOAfmyioHwZtYv2VA==" + }, "regenerate": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", @@ -6793,6 +6923,11 @@ "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.5.tgz", "integrity": "sha512-C34cIU4+DB2vMyAbmEKossWq2ZQDr6QEyuuCzWrM9zfw1sGc0mYiJ0UnG9zzNykt49C2Fi34hvr2vssFQRS6EA==" }, + "x-xss-protection": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/x-xss-protection/-/x-xss-protection-1.3.0.tgz", + "integrity": "sha512-kpyBI9TlVipZO4diReZMAHWtS0MMa/7Kgx8hwG/EuZLiA6sg4Ah/4TRdASHhRRN3boobzcYgFRUFSgHRge6Qhg==" + }, "xdg-basedir": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-3.0.0.tgz", diff --git a/package.json b/package.json index b2a7fe9..9809729 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "uc-voice-of-customer", - "version": "1.0.0", - "description": "voice of customer", + "name": "boiler-plate-version-two", + "version": "2.0.0", + "description": "boiler plate version two", "main": "index.js", "engine": { "node": "10.16.0", @@ -21,19 +21,14 @@ "cookie-parser": "^1.4.4", "cors": "^2.8.5", "crypto": "^1.0.1", - "dialogflow": "^1.1.2", - "dialogflow-fulfillment": "^0.6.1", "express": "^4.17.1", "fluent-ffmpeg": "^2.1.2", + "helmet": "^3.22.0", "jsonwebtoken": "^8.5.1", "moment": "^2.24.0", "mongoose": "^5.4.20", - "mongoose-sequence": "^5.2.2", "multer": "^1.4.2", - "nodemailer": "^6.4.2", - "saslprep": "^1.0.3", - "socket.io": "^2.2.0", - "store": "^2.0.12" + "nodemailer": "^6.4.2" }, "devDependencies": { "concurrently": "^4.1.0", @@ -43,4 +38,4 @@ "babel-preset-env": "^1.7.0", "morgan": "^1.9.1" } -} +} \ No newline at end of file diff --git a/server/index.js b/server/index.js index 3c96b99..bc195b3 100644 --- a/server/index.js +++ b/server/index.js @@ -6,20 +6,30 @@ import bodyParser from 'body-parser'; import cookieParser from 'cookie-parser'; import morgan from 'morgan'; import config from './config/key'; +import helmet from 'helmet'; const app = express(); mongoose.connect(config.mongoURI, - { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false }) + { + useNewUrlParser: true, + useUnifiedTopology: true, + useFindAndModify: false, + useCreateIndex: true + }) .then(() => console.log('MongoDB Connected...')) - .catch(err => console.log(err)); + .catch(err => console.error(err)); //to not get any deprecation warning or error //support parsing of application/x-www-form-urlencoded post data app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); + app.use(cookieParser()); +// Helmet helps you secure your Express apps by setting various HTTP headers. +app.use(helmet()) + // Logger Middleware app.use(morgan('dev')); diff --git a/server/models/user.js b/server/models/user.js index b6b4603..0729123 100644 --- a/server/models/user.js +++ b/server/models/user.js @@ -6,12 +6,6 @@ const moment = require("moment"); const crypto = require('crypto'); const userSchema = mongoose.Schema({ - account: { - type: String, - maxlength: 20, - unique: true, - trim: true, - }, name: { type: String, maxlength: 50 @@ -25,29 +19,18 @@ const userSchema = mongoose.Schema({ type: String, minglength: 5 }, - // lastname: { - // type:String, - // maxlength: 50 - // }, role: { type: Number, default: 0 }, image: String, - token: { - type: String, - }, - tokenExp: { - type: Number - }, - resetToken: { - type: String - }, - resetTokenExp: { - type: Number - } + token: String, + tokenExp: Number, + resetToken: String, + resetTokenExp: Number }) - +//role === 1 normal user +//role === 0 admin user userSchema.pre('save', function (next) { var user = this; @@ -116,6 +99,21 @@ userSchema.methods.generateResetToken = function (cb) { }) } +/** + * Helper method for getting user's gravatar. + */ +userSchema.methods.gravatar = function gravatar(size) { + if (!size) { + size = 200; + } + if (!this.email) { + return `https://gravatar.com/avatar/?s=${size}&d=retro`; + } + const md5 = crypto.createHash('md5').update(this.email).digest('hex'); + return `https://gravatar.com/avatar/${md5}?s=${size}&d=retro`; +}; + + const User = mongoose.model('User', userSchema); module.exports = { User } \ No newline at end of file diff --git a/server/routes/users.js b/server/routes/users.js index e345fa9..301d5d0 100644 --- a/server/routes/users.js +++ b/server/routes/users.js @@ -20,17 +20,17 @@ router.get("/auth", auth, (req, res) => { }); }); -router.post("/register", (req, res) => { +router.post("/register", async (req, res) => { const user = new User(req.body); - - user.save((err, doc) => { - console.log(doc) - if (err) return res.json({ success: false, err }); + try { + await user.save() return res.status(200).json({ success: true }); - }); + } catch (err) { + console.log(err) + } }); router.post("/login", (req, res) => { @@ -58,13 +58,15 @@ router.post("/login", (req, res) => { }); }); -router.get("/logout", auth, (req, res) => { - User.findOneAndUpdate({ _id: req.user._id }, { token: "", tokenExp: "" }, (err, doc) => { - if (err) return res.json({ success: false, err }); +router.get("/logout", auth, async (req, res) => { + try { + await User.findOneAndUpdate({ _id: req.user._id }, { token: "", tokenExp: "" }) return res.status(200).send({ success: true }); - }); + } catch (error) { + console.log(error) + } }); module.exports = router;