mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
|
|
module.exports = adduser
|
|
|
|
var registry = require("./utils/npm-registry-client/index.js")
|
|
, ini = require("./utils/ini.js")
|
|
, log = require("./utils/log.js")
|
|
, npm = require("./npm.js")
|
|
, prompt = require("./utils/prompt.js")
|
|
, promiseChain = require("./utils/promise-chain.js")
|
|
, crypto
|
|
|
|
try {
|
|
crypto = process.binding("crypto") && require("crypto")
|
|
} catch (ex) {}
|
|
|
|
adduser.usage = "npm adduser\nThen enter stuff at the prompts"
|
|
|
|
function adduser (args, cb) {
|
|
if (!crypto) return cb(new Error(
|
|
"You must compile node with ssl support to use the adduser feature"))
|
|
|
|
var u = { u : npm.config.get("username")
|
|
, p : npm.config.get("_password")
|
|
, e : npm.config.get("email")
|
|
}
|
|
, changed = false
|
|
|
|
promiseChain(cb)
|
|
(prompt, ["Username: ", u.u], function (un) {
|
|
changed = u.u !== un
|
|
u.u = un
|
|
})
|
|
(function (cb) {
|
|
if (u.p && !changed) return cb(null, u.p)
|
|
prompt("Password: ", u.p, true, cb)
|
|
}, [], function (pw) { u.p = pw })
|
|
(prompt, ["Email: ", u.e], function (em) { u.e = em })
|
|
(function (cb) {
|
|
if (changed) npm.config.del("_auth")
|
|
registry.adduser(u.u, u.p, u.e, function (er) {
|
|
if (er) return cb(er)
|
|
ini.set("username", u.u, "user")
|
|
ini.set("_password", u.p, "user")
|
|
ini.set("email", u.e, "user")
|
|
log("Authorized user " + u.u, "adduser")
|
|
ini.save("user", cb)
|
|
})
|
|
})
|
|
()
|
|
}
|
|
|