mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
Added the ability to add users
This commit is contained in:
parent
dbf3301ff9
commit
99b8c31d3a
4 changed files with 47 additions and 7 deletions
|
@ -1,7 +1,8 @@
|
|||
var assert = require('assert')
|
||||
, crypto = require('crypto')
|
||||
, minimatch = require('minimatch')
|
||||
, utils = require('./utils')
|
||||
, users = require('./users')
|
||||
, utils = require('./utils');
|
||||
|
||||
// [[a, [b, c]], d] -> [a, b, c, d]
|
||||
function flatten(array) {
|
||||
|
@ -147,8 +148,12 @@ Config.prototype.get_package_setting = function(package, setting) {
|
|||
}
|
||||
|
||||
Config.prototype.authenticate = function(user, password) {
|
||||
if (this.users[user] == null) return false
|
||||
return crypto.createHash('sha1').update(password).digest('hex') === this.users[user].password
|
||||
if(!users.users[user]) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return crypto.createHash('sha1').update(password).digest('hex') === users.users[user].password
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Config
|
||||
|
|
11
lib/index.js
11
lib/index.js
|
@ -16,6 +16,7 @@ var express = require('express')
|
|||
, localList = require('./local-list')
|
||||
, search = require('./search')
|
||||
, _ = require('underscore')
|
||||
, users = require('./users')
|
||||
, marked = require('marked');
|
||||
|
||||
function match(regexp) {
|
||||
|
@ -209,10 +210,12 @@ module.exports = function(config_hash) {
|
|||
})
|
||||
|
||||
app.put('/-/user/:org_couchdb_user', function(req, res, next) {
|
||||
res.status(409)
|
||||
return res.send({
|
||||
error: 'registration is not implemented',
|
||||
})
|
||||
users.add(req.body, function(err) {
|
||||
res.status(409)
|
||||
return res.send({
|
||||
error: 'registration is not implemented',
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
app.put('/-/user/:org_couchdb_user/-rev/*', function(req, res, next) {
|
||||
|
|
BIN
lib/static/favicon.ico
Normal file
BIN
lib/static/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
32
lib/users.js
Normal file
32
lib/users.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
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
|
||||
params.password = crypto.createHash('sha1').update(params.password).digest('hex');
|
||||
|
||||
//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();
|
Loading…
Reference in a new issue