1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/lib/users.js
2014-05-09 13:26:47 -05:00

38 lines
807 B
JavaScript

var fs = require('fs')
, crypto = require('crypto')
, usersPath = './users.json';
var Users = function() {
if(fs.existsSync(usersPath)) {
this.users = JSON.parse(fs.readFileSync(usersPath, 'utf8'));
}
else {
this.users = {};
}
};
Users.prototype = {
add: function(params, callback) {
//Hash the Password
if(params.password) {
params.password = crypto.createHash('sha1').update(params.password).digest('hex');
}
else if(params.password_sha) {
params.password = params.password_sha;
}
//Save
this.users[params.name] = params;
this.sync(callback);
},
remove: function(name, callback) {
delete this.users[name];
this.sync(callback);
},
sync: function(callback) {
fs.writeFile(usersPath, JSON.stringify(this.users), callback);
}
};
module.exports = new Users();