diff options
author | isaacs <i@izs.me> | 2012-08-21 15:29:03 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-08-21 15:29:37 -0700 |
commit | 2bcb9ab7bcd474590f109bd04c43ba8e39a90dfa (patch) | |
tree | 225e7199ccab16b9d8fad19c5001a0a4991f5f07 /deps/npm/node_modules/npm-registry-client/lib/adduser.js | |
parent | badbd1af27f5f3fd07862b8ee7d0810e7ae9ef56 (diff) | |
download | android-node-v8-2bcb9ab7bcd474590f109bd04c43ba8e39a90dfa.tar.gz android-node-v8-2bcb9ab7bcd474590f109bd04c43ba8e39a90dfa.tar.bz2 android-node-v8-2bcb9ab7bcd474590f109bd04c43ba8e39a90dfa.zip |
npm: Upgrade to 1.1.55
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 | 46 |
1 files changed, 20 insertions, 26 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 f940ca1ca5..7106e444d7 100644 --- a/deps/npm/node_modules/npm-registry-client/lib/adduser.js +++ b/deps/npm/node_modules/npm-registry-client/lib/adduser.js @@ -1,18 +1,12 @@ - module.exports = adduser -var uuid = require("node-uuid") - , crypto - -try { -} catch (ex) {} +var crypto = require('crypto') function sha (s) { return crypto.createHash("sha1").update(s).digest("hex") } function adduser (username, password, email, cb) { - if (!crypto) crypto = require("crypto") password = ("" + (password || "")).trim() if (!password) return cb(new Error("No password supplied.")) @@ -27,7 +21,7 @@ function adduser (username, password, email, cb) { "Sorry, ':' chars are not allowed in passwords.\n"+ "See <https://issues.apache.org/jira/browse/COUCHDB-969> for why.")) - var salt = uuid() + var salt = crypto.randomBytes(30).toString('hex') , userobj = { name : username , salt : salt @@ -41,18 +35,18 @@ function adduser (username, password, email, 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 + var pre = { username: this.conf.get('username') + , password: this.conf.get('_password') + , auth: this.conf.get('_auth') + , token: this.conf.get('_token') } + + this.conf.del('_token') + this.conf.del('username') + this.conf.del('_auth') + this.conf.del('_password') if (this.couchLogin) { this.couchLogin.token = null } - this.username = null - this.password = null - this.auth = null cb = done.call(this, cb, pre) @@ -72,13 +66,13 @@ function adduser (username, password, email, cb) { , function (error, data, json, response) { // if it worked, then we just created a new user, and all is well. // but if we're updating a current record, then it'll 409 first - if (error && !this.auth) { + if (error && !this.conf.get('_auth')) { // must be trying to re-auth on a new machine. // use this info as auth var b = new Buffer(username + ":" + password) - this.auth = b.toString("base64") - this.username = username - this.password = password + this.conf.set('_auth', b.toString("base64")) + this.conf.set('username', username) + this.conf.set('_password', password) } if (!error || !response || response.statusCode !== 409) { @@ -114,16 +108,16 @@ function done (cb, pre) { } // there was some kind of error, re-instate previous auth/token/etc. - this.token = pre.token + this.conf.set('_token', pre.token) if (this.couchLogin) { - this.couchLogin.token = this.token + this.couchLogin.token = pre.token if (this.couchLogin.tokenSet) { this.couchLogin.tokenSet(pre.token) } } - this.username = pre.username - this.password = pre.password - this.auth = pre.auth + this.conf.set('username', pre.username) + this.conf.set('_password', pre.password) + this.conf.set('_auth', pre.auth) this.log.verbose("adduser", "back", [error, data, json]) if (!error) { |