-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
64 lines (56 loc) · 1.45 KB
/
db.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* eslint-disable no-multi-str */
var crypto = require('crypto');
var sqlite3 = require('sqlite3');
var mkdirp = require('mkdirp');
mkdirp.sync('./var/db');
var db = new sqlite3.Database('./var/db/bonsai.db');
db.serialize(() => {
// create the database schema for the todos app
db.run(
'CREATE TABLE IF NOT EXISTS users ( \
id INTEGER PRIMARY KEY, \
username TEXT UNIQUE, \
hashed_password BLOB, \
salt BLOB, \
name TEXT, \
mailchain_address TEXT UNIQUE, \
mailchain_address_verified INTEGER, \
email TEXT UNIQUE, \
email_verified INTEGER \
)',
);
db.run(
'CREATE TABLE IF NOT EXISTS federated_credentials ( \
id INTEGER PRIMARY KEY, \
user_id INTEGER NOT NULL, \
provider TEXT NOT NULL, \
subject TEXT NOT NULL, \
UNIQUE (provider, subject) \
)',
);
db.run(
'CREATE TABLE IF NOT EXISTS bonsai ( \
id INTEGER PRIMARY KEY, \
owner_id INTEGER NOT NULL, \
title TEXT NOT NULL, \
completed INTEGER \
)',
);
db.run(
'CREATE TABLE IF NOT EXISTS scammers ( \
id INTEGER PRIMARY KEY, \
phone_number INTEGER, \
name TEXT, \
aliases TEXT, \
numbers INTEGER, \
)',
);
// create an initial user (username: alice, password: letmein)
var salt = crypto.randomBytes(16);
db.run('INSERT OR IGNORE INTO users (username, hashed_password, salt) VALUES (?, ?, ?)', [
'alice',
crypto.pbkdf2Sync('letmein', salt, 310000, 32, 'sha256'),
salt,
]);
});
module.exports = db;