This repository has been archived by the owner on Sep 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
132 lines (127 loc) · 3.61 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var thinky = require('thinky')({
db: 'lockdown',
min: 10
}),
r = thinky.r,
validator = require('validator'),
config = require('./config');
def = {
User: thinky.createModel('Users', {
id: String,
username: {
_type: String,
validator: function(username) {
return validator.isLength(username, 3, 64) && validator.isAlphanumeric(username) && validator.isLowercase(username);
}
},
displayUsername: {
_type: String,
validator: function(username) {
return validator.isLength(username, 3, 64) && validator.isAlphanumeric(username);
}
},
passHash: {
_type: String,
validator: function(hash) {
return validator.isLength(hash, 128);
}
},
passSalt: {
_type: String,
validator: function(salt) {
salt = salt.replace(/=/g, '');
return validator.isLength(salt, Math.ceil(config.crypt.saltLength * 4 / 3));
}
},
passIter: Number,
passHashSize: Number,
passHashVersion: {
_type: Number,
default: 1
},
timestamp: {
_type: Date,
default: r.now(),
options: {
enforce_extra: false
}
},
sites: {
_type: Object,
default: {},
schema: {
username: String,
password: String,
domain: String,
url: String,
program: String,
type: String
}
},
email: {
_type: String,
validator: function(email) {
return validator.isEmail(email);
}
},
userValidation: {
_type: Object,
schema: {
confirmed: {
_type: Boolean,
default: false
},
token: {
_type: String,
validator: function(tkn) {
return tkn.length === 4;
},
default: (Math.floor(Math.random() * 9000) + 1000).toString()
},
link: {
_type: String,
validator: function(link) {
return validator.isAlphanumeric(link) && link.length === 64;
},
default: 'xxxxxxxx'.replace(/x/g, function(c) {
return (Math.random() * 1e16).toString(36).slice(0, 8);
})
}
},
options: {
enforce_type: 'loose'
}
},
settings: {
_type: Object, // more to come later
schema: {
passwordReminder: String
},
enforce_missing: false
}
}, {
enforce_type: 'strict', // Do not allow null to be a valid value
enforce_extra: true // do not allow extra data
}),
Stats: thinky.createModel('Stats', {
id: String,
stat: String,
timestamp: {
_type: Date,
default: r.now()
}
}),
Config: thinky.createModel('Config', {
id: String,
timestamp: {
_type: Date,
default: r.now(),
options: {
enforce_extra: false
}
}
}),
r: r
};
def.User.ensureIndex('username');
module.exports = def;