Skip to content

Commit

Permalink
added missing alias for setup script; added user cleaner to remove pa…
Browse files Browse the repository at this point in the history
…ssword hashes from user object returns; fixed multiple issues with setup variable setting
  • Loading branch information
rastenis committed Aug 14, 2019
1 parent 114217d commit 73065f0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Demo website coming soon™.
# install dependencies
$ npm install

# run config
$ npm run config
# run setup
$ npm run setup

# serve with hot reload at localhost:3000
$ npm run dev
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "1.0.1",
"description": "A vue/nuxtjs/passport/bulma boilerplate for express.",
"author": "Scharkee",
"private": true,
"scripts": {
"dev": "node src/server.js",
"build": "nuxt build",
Expand All @@ -13,6 +12,7 @@
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"test": "ava --serial --verbose",
"setup": "node setup.js",
"config": "npm run setup",
"setup:headless": "node setup.js --headless"
},
"dependencies": {
Expand Down
22 changes: 13 additions & 9 deletions setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ let passportKeys = require("./config/passportKeysExample.json");

fs.ensureDirSync("./db/");

if (process.argv[2]=="--headless") {
if (process.argv[2] == "--headless") {
// saving defaults
fs.copySync('./config/configExample.json', './config/config.json')
fs.copySync('./config/passportKeysExample.json', './config/passportKeys.json')
fs.copySync("./config/configExample.json", "./config/config.json");
fs.copySync(
"./config/passportKeysExample.json",
"./config/passportKeys.json"
);
process.exit(0);
}

Expand All @@ -19,7 +22,7 @@ console.log("Starting setup...");
config.self_hosted =
prompt(
"Use Auto-generated TLS? (will require ports 80 and 443) (y/N): ",
false
"n"
).toLowerCase() == "y";

if (config.self_hosted) {
Expand All @@ -28,7 +31,7 @@ if (config.self_hosted) {
config.tls.tos =
prompt(
"Do you agree with the LetsEncrypt TOS? (Y/n): ",
true
"y"
).toLowerCase() == "y";

if (!config.tls.tos) {
Expand All @@ -52,10 +55,11 @@ if (config.self_hosted) {

if (!config.self_hosted) {
config.port = ~~prompt("Enter port (7777): ", config.port);
config.secure_override = ~~prompt(
"Will you use an external HTTPS/TLS provider proxy? Secure cookies will be enabled, if yes (y/N): ",
false
);
config.secure_override =
~~prompt(
"Will you use an external HTTPS/TLS provider proxy? Secure cookies will be enabled, if yes (y/N): ",
"n"
).toLowerCase() == "y";
}

if (
Expand Down
5 changes: 5 additions & 0 deletions src/external/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const utilities = {
msg: message || "An error has occured."
}
};
},
cleanUser: function cleanUser(user) {
delete user.data.password;
delete user._data.password;
return user;
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ app.post("/login", (req, res) => {
meta: {
error: false
},
user: user
user: utils.cleanUser(Object.assign({}, user))
});
});
})(req, res);
Expand Down Expand Up @@ -231,7 +231,7 @@ app.post("/register", (req, res, next) => {
error: false,
msg: "You have successfully registered!"
},
user: newDoc
user: utils.cleanUser(Object.assign({}, newDoc))
});
}
);
Expand Down Expand Up @@ -293,7 +293,7 @@ app.patch("/changePassword", (req, res) => {
})
.then(r => {
return res.json({
user: r,
user: utils.cleanUser(Object.assign({}, r)),
meta: {
error: false,
msg: "You have successfully changed your password!"
Expand Down Expand Up @@ -327,7 +327,7 @@ app.post("/unlink", (req, res) => {

user.saveUser().then(r => {
return res.json({
user: user,
user: utils.cleanUser(Object.assign({}, user)),
meta: {
error: false,
msg: `You have successfully unlinked your ${req.body.toUnlink} account!`
Expand Down

0 comments on commit 73065f0

Please sign in to comment.