Adding test user
This commit is contained in:
@@ -3,7 +3,7 @@ import path from 'path'
|
||||
import timers from 'timers'
|
||||
import autoBind from 'auto-bind2'
|
||||
|
||||
export class DARServer {
|
||||
export class ServerTool {
|
||||
constructor(toolName, log) {
|
||||
autoBind(this)
|
||||
this.toolName = toolName
|
||||
37
server/src/bin/addUser.js
Normal file
37
server/src/bin/addUser.js
Normal 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)
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
import { DARServer } from './DARServer'
|
||||
import { ServerTool } from './ServerTool'
|
||||
import pino from 'pino'
|
||||
import * as pinoExpress from 'pino-pretty-express'
|
||||
import path from 'path'
|
||||
@@ -18,7 +18,7 @@ if (isProduction) {
|
||||
log = pino({ name: serviceName }, pretty)
|
||||
}
|
||||
|
||||
const tool = new DARServer(path.basename(process.argv[1], '.js'), log)
|
||||
const tool = new ServerTool(path.basename(process.argv[1], '.js'), log)
|
||||
|
||||
tool.run(process.argv.slice(2)).then((exitCode) => {
|
||||
process.exitCode = exitCode
|
||||
Reference in New Issue
Block a user