-
Notifications
You must be signed in to change notification settings - Fork 1
/
3.2.js
executable file
·46 lines (41 loc) · 971 Bytes
/
3.2.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
var bcrypt = require('bcrypt');
function series(steps, callback) {
var stepfns = steps.slice();
function doNext() {
var next = stepfns.shift();
var args = [].slice.call(arguments);
if (next) {
next.apply(null, args.concat(function (err, result) {
if (err) { return callback(err); }
doNext(result);
}));
} else {
callback.apply(null, [undefined].concat(args));
}
}
doNext();
}
function save(user, callback) {
series([
function (next) {
bcrypt.genSalt(10, next);
},
function (salt, next) {
bcrypt.hash(user.password, salt, next);
},
function (hash, next) {
db.put(user.username, {
username: user.username,
salt: salt,
passwordHash: hash,
games: []
}, next);
}
], function (err, user) {
if (err) { return callback(err); }
callback(undefined, {
username: user.username,
games: user.games
});
});
}