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

38 lines
807 B
JavaScript
Raw Normal View History

2014-05-09 02:24:41 +02:00
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;
}
2014-05-09 02:24:41 +02:00
//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();