-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathinit-root-user.js
34 lines (30 loc) · 1.02 KB
/
init-root-user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const config = require('../../conf/config')
const UserModel = require('../model/user')
const util = require('./util')
/* istanbul ignore next */
async function createUser(username, nickname, manager) {
const user = await UserModel.findOne({where: {username}})
if (user) {
console.log('user [%s] is exist!', username);
return;
}
const password = config.rootUserInitialPassword || util.randomString(12)
const values = {username, nickname, manager}
values.password = util.encodePassword(password);
values.status = 0;
values.lastLogin = 0;
values.createTime = util.unixtime();
values.updateTime = util.unixtime();
await UserModel.create(values);
console.log('system user [%s] created, the password is %s.', username, password)
}
async function addRootUser() {
await createUser('root', 'root(super man)', 'super')
await createUser('admin', 'administrator', 'admin')
}
setTimeout(()=> {
addRootUser().then(() => {
}).catch((err) => {
console.log('create root user failed! err: %s', err)
})
}, 1000 * 1);