Files
2024-10-10 21:57:37 +03:30

32 lines
909 B
JavaScript

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)
}
}
})
}