-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdefault_db_users.js
54 lines (42 loc) · 1.09 KB
/
default_db_users.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
/*jshint node:true */
'use strict';
var db = []
, _ = require('lodash');
function DefaultDBUsers(id, username, password) {
this.id = id;
this.username = username;
this.password = password;
}
DefaultDBUsers.prototype.comparePassword = function(candidatePassword, cb) {
cb(null, this.password == candidatePassword);
};
DefaultDBUsers.prototype.toObject = function() {
return _.clone(this);
};
DefaultDBUsers.prototype.isActive = function() {
return this.active
};
DefaultDBUsers.prototype.save = function(cb) {
db.push(this);
if (cb) { cb(null, this); }
};
DefaultDBUsers.prototype.passwordIsOk = DefaultDBUsers.prototype.comparePassword;
DefaultDBUsers.findOneByUsername = function(username, cb) {
var res = _.find(db, function(item) {
return item.username == username;
});
if (res) {
return cb(null, res);
}
return cb(null, false);
};
DefaultDBUsers.findOneById = function(user_id, cb) {
var res = _.find(db, function(item) {
return item.id == user_id;
});
if (res) {
return cb(null, res);
}
return cb(null, false);
};
module.exports = DefaultDBUsers;