diff options
author | isaacs <i@izs.me> | 2012-07-24 12:34:13 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-07-24 12:34:13 -0700 |
commit | 0a0002b480dc40ecd94c542d1101e87404a47692 (patch) | |
tree | 53148415db52f4f4ccf7dad1c0e0b4ccf504b64d /deps/npm/node_modules/npm-registry-client/lib/adduser.js | |
parent | 43a0c8811627ea224bb18ba3c72b91ca2c4ea8d7 (diff) | |
download | android-node-v8-0a0002b480dc40ecd94c542d1101e87404a47692.tar.gz android-node-v8-0a0002b480dc40ecd94c542d1101e87404a47692.tar.bz2 android-node-v8-0a0002b480dc40ecd94c542d1101e87404a47692.zip |
npm: Upgrade to 1.1.45
This includes node-gyp 0.6.1
Diffstat (limited to 'deps/npm/node_modules/npm-registry-client/lib/adduser.js')
-rw-r--r-- | deps/npm/node_modules/npm-registry-client/lib/adduser.js | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/deps/npm/node_modules/npm-registry-client/lib/adduser.js b/deps/npm/node_modules/npm-registry-client/lib/adduser.js index 48a0359529..f940ca1ca5 100644 --- a/deps/npm/node_modules/npm-registry-client/lib/adduser.js +++ b/deps/npm/node_modules/npm-registry-client/lib/adduser.js @@ -39,9 +39,33 @@ function adduser (username, password, email, cb) { , date: new Date().toISOString() } - cb = done.call(this, cb) + // pluck off any other username/password/token. it needs to be the + // same as the user we're becoming now. replace them on error. + var pre = { username: this.username + , password: this.password + , auth: this.auth + , token: this.token } + + this.token = null + if (this.couchLogin) { + this.couchLogin.token = null + } + this.username = null + this.password = null + this.auth = null + + cb = done.call(this, cb, pre) + + var logObj = Object.keys(userobj).map(function (k) { + if (k === 'salt' || k === 'password_sha') return [k, 'XXXXX'] + return [k, userobj[k]] + }).reduce(function (s, kv) { + s[kv[0]] = kv[1] + return s + }, {}) + + this.log.verbose("adduser", "before first PUT", logObj) - this.log.verbose("adduser", "before first PUT", userobj) this.request('PUT' , '/-/user/org.couchdb.user:'+encodeURIComponent(username) , userobj @@ -53,6 +77,8 @@ function adduser (username, password, email, cb) { // use this info as auth var b = new Buffer(username + ":" + password) this.auth = b.toString("base64") + this.username = username + this.password = password } if (!error || !response || response.statusCode !== 409) { @@ -71,7 +97,7 @@ function adduser (username, password, email, cb) { userobj[k] = data[k] } }) - this.log.verbose("adduser", "userobj", userobj) + this.log.verbose("adduser", "userobj", logObj) this.request('PUT' , '/-/user/org.couchdb.user:'+encodeURIComponent(username) + "/-rev/" + userobj._rev @@ -81,11 +107,24 @@ function adduser (username, password, email, cb) { }.bind(this)) } -function done (cb) { +function done (cb, pre) { return function (error, data, json, response) { if (!error && (!response || response.statusCode === 201)) { return cb(error, data, json, response) } + + // there was some kind of error, re-instate previous auth/token/etc. + this.token = pre.token + if (this.couchLogin) { + this.couchLogin.token = this.token + if (this.couchLogin.tokenSet) { + this.couchLogin.tokenSet(pre.token) + } + } + this.username = pre.username + this.password = pre.password + this.auth = pre.auth + this.log.verbose("adduser", "back", [error, data, json]) if (!error) { error = new Error( (response && response.statusCode || "") + " "+ |