-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
20 lines (19 loc) · 875 Bytes
/
setup.js
File metadata and controls
20 lines (19 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const InternRepository = require('./persistence/intern-repository.js');
const {Intern, Admin} = require('./models/interns.js');
const crypto = require('crypto');
(async function() {
//
let password = 'password';
let salt = crypto.randomBytes(16).toString('base64');
let hash = crypto.createHmac('sha512', salt).update(password.normalize()).digest('base64');
password = salt + '$' + hash;
const defaultAdmin = new Admin(1, 'Default', 'User', 'defaultuser', password);
const repo = await InternRepository.load();
let rows = await repo.getAll();
if (rows.length <= 0) {
// Sheet is empty. Create default admin.
console.log('Sheet is empty.');
const result = await repo.add(defaultAdmin);
console.log(`Default admin created. Username: ${defaultAdmin.username}\nPassword: ${defaultAdmin.password}`);
}
})();