Adding test user
This commit is contained in:
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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user