Adding test user

This commit is contained in:
John Lyon-Smith
2018-02-28 13:42:02 -08:00
parent eb54ca0b62
commit 5889f7655a
6 changed files with 70 additions and 3 deletions

37
server/src/bin/addUser.js Normal file
View File

@@ -0,0 +1,37 @@
import path from 'path'
import config from 'config'
import mongoose from 'mongoose'
import { DB } from '../database'
import credential from 'credential'
import readlineSync from 'readline-sync'
import crypto from 'crypto'
import urlSafeBase64 from 'urlsafe-base64'
import util from 'util'
const mongoUri = config.get('uri.mongo')
new DB().connect(mongoUri).then((db) => {
console.log(`Connected to MongoDB at ${mongoUri}`)
const User = db.User
let user = new User({
role: "administrator"
})
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)
})
})