update:add ci cd files ==> do not edit those file
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
const User = require('../models/User')
|
||||
const _privateAdminInfo = require('./privateAdminData')
|
||||
const bcrypt = require('bcryptjs')
|
||||
const database = require('../database')
|
||||
|
||||
module.exports.createAdmins = () => {
|
||||
database.once('open', async cb => {
|
||||
for (const item of _privateAdminInfo) {
|
||||
try {
|
||||
const user = await User.findOne({username: item.username})
|
||||
if (!user) {
|
||||
const data = {
|
||||
username: item.username,
|
||||
scope: ['admin']
|
||||
}
|
||||
// hash password
|
||||
const salt = await bcrypt.genSalt(10)
|
||||
const hash = await bcrypt.hash(item.password, salt)
|
||||
data.password = hash
|
||||
const newUser = new User(data)
|
||||
newUser.save(err => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
}
|
||||
} catch
|
||||
(e) {
|
||||
console.log('Private admin creation has error -- ', e)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user