Working login on mobile
This commit is contained in:
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user