bugfixes for htpasswd authentication

This commit is contained in:
Alex Kocharin 2014-07-22 23:48:15 +04:00
parent 9275b2cc85
commit a528811e35
2 changed files with 9 additions and 4 deletions

View File

@ -158,9 +158,9 @@ Config.prototype.get_package_setting = function(package, setting) {
}
Config.prototype.authenticate = function(user, password, cb) {
if (this.users != null) {
if (this.users[user] == null) return cb(null, false)
if (crypto.createHash('sha1').update(password).digest('hex') === this.users[user].password) return cb(null, true)
if (this.users != null && this.users[user] != null) {
// if user exists in this.users, verify password against it no matter what is in htpasswd
return cb(null, crypto.createHash('sha1').update(password).digest('hex') === this.users[user].password)
}
if (!this.HTPasswd) return cb(null, false)
@ -170,6 +170,11 @@ Config.prototype.authenticate = function(user, password, cb) {
}
Config.prototype.add_user = function(user, password, cb) {
if (this.users && this.users[user]) return cb(new UError({
status: 409,
message: 'this user already exists',
}))
if (this.HTPasswd) {
if (this.max_users || this.max_users == null) {
var max_users = Number(this.max_users || Infinity)

View File

@ -223,7 +223,7 @@ module.exports = function(config_hash) {
res.status(201)
return res.send({
ok: 'user "' + req.remoteUser + '" created',
ok: 'user "' + req.body.name + '" created',
})
})
}