Server deployment stuff
This commit is contained in:
@@ -10,7 +10,7 @@ import util from 'util'
|
||||
|
||||
import autoBind from 'auto-bind2'
|
||||
|
||||
class SendMessageTool {
|
||||
class AddUserTool {
|
||||
constructor(toolName, log) {
|
||||
autoBind(this)
|
||||
this.toolName = toolName
|
||||
@@ -20,7 +20,9 @@ class SendMessageTool {
|
||||
async run() {
|
||||
const mongoUri = config.get('uri.mongo')
|
||||
|
||||
new DB().connect(mongoUri).then((db) => {
|
||||
try {
|
||||
const db = await new DB().connect(mongoUri)
|
||||
|
||||
console.log(`Connected to MongoDB at ${mongoUri}`)
|
||||
|
||||
const User = db.User
|
||||
@@ -33,18 +35,16 @@ class SendMessageTool {
|
||||
let password = readlineSync.question('Password? ', {hideEchoBack: true})
|
||||
let cr = credential()
|
||||
|
||||
util.promisify(cr.hash)(password).then((json) => {
|
||||
user.passwordHash = JSON.parse(json)
|
||||
const json = await util.promisify(cr.hash)(password)
|
||||
|
||||
return user.save()
|
||||
}).then((savedUser) => {
|
||||
console.log(`User is ${user}`)
|
||||
process.exit(0)
|
||||
}).catch((error) => {
|
||||
console.log(`error: ${error.message}`)
|
||||
process.exit(-1)
|
||||
})
|
||||
})
|
||||
user.passwordHash = JSON.parse(json)
|
||||
|
||||
const savedUser = await user.save()
|
||||
|
||||
console.log(`User is ${user}`)
|
||||
} catch(error) {
|
||||
console.log(`error: ${error.message}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ const log = {
|
||||
warning: function() { console.error(chalk.yellow('warning:', [...arguments].join(' ')))}
|
||||
}
|
||||
|
||||
const tool = new AddUserTool('add-user', log)
|
||||
const tool = new AddUserTool('addUser', log)
|
||||
|
||||
tool.run(process.argv.slice(2)).then((exitCode) => {
|
||||
process.exit(exitCode)
|
||||
|
||||
@@ -110,7 +110,7 @@ const log = {
|
||||
warning: function() { console.error(chalk.yellow('warning:', [...arguments].join(' ')))}
|
||||
}
|
||||
|
||||
const tool = new SendMessageTool('send-message', log)
|
||||
const tool = new SendMessageTool('sendMessage', log)
|
||||
|
||||
tool.run(process.argv.slice(2)).then((exitCode) => {
|
||||
process.exit(exitCode)
|
||||
|
||||
Reference in New Issue
Block a user