Working login on mobile

This commit is contained in:
John Lyon-Smith
2018-03-12 19:11:13 -07:00
parent eeb3eb4947
commit e7aaa014ff
19 changed files with 10606 additions and 131 deletions

View File

@@ -8,30 +8,56 @@ import crypto from 'crypto'
import urlSafeBase64 from 'urlsafe-base64'
import util from 'util'
const mongoUri = config.get('uri.mongo')
import autoBind from 'auto-bind2'
new DB().connect(mongoUri).then((db) => {
console.log(`Connected to MongoDB at ${mongoUri}`)
class SendMessageTool {
constructor(toolName, log) {
autoBind(this)
this.toolName = toolName
this.log = log
}
const User = db.User
let user = new User({
administrator: true,
})
user.firstName = readlineSync.question('First name? ')
user.lastName = readlineSync.question('Last name? ')
user.email = readlineSync.question('Email? ')
let password = readlineSync.question('Password? ', {hideEchoBack: true})
let cr = credential()
async run() {
const mongoUri = config.get('uri.mongo')
util.promisify(cr.hash)(password).then((json) => {
user.passwordHash = JSON.parse(json)
new DB().connect(mongoUri).then((db) => {
console.log(`Connected to MongoDB at ${mongoUri}`)
return user.save()
}).then((savedUser) => {
console.log(`User is ${user}`)
process.exit(0)
}).catch((error) => {
console.log(`error: ${error.message}`)
process.exit(-1)
})
const User = db.User
let user = new User({
administrator: true,
})
user.firstName = readlineSync.question('First name? ')
user.lastName = readlineSync.question('Last name? ')
user.email = readlineSync.question('Email? ')
let password = readlineSync.question('Password? ', {hideEchoBack: true})
let cr = credential()
util.promisify(cr.hash)(password).then((json) => {
user.passwordHash = JSON.parse(json)
return user.save()
}).then((savedUser) => {
console.log(`User is ${user}`)
process.exit(0)
}).catch((error) => {
console.log(`error: ${error.message}`)
process.exit(-1)
})
})
}
}
const log = {
info: console.info,
error: function() { console.error(chalk.red('error:', [...arguments].join(' ')))},
warning: function() { console.error(chalk.yellow('warning:', [...arguments].join(' ')))}
}
const tool = new AddUserTool('add-user', log)
tool.run(process.argv.slice(2)).then((exitCode) => {
process.exit(exitCode)
}).catch((err) => {
console.error(err)
})