diff --git a/README.markdown b/README.markdown index 3f27e81..e544bb2 100644 --- a/README.markdown +++ b/README.markdown @@ -58,6 +58,12 @@ comp.on("online", function(){ function(err){ /*...*/ } ); + // receive a user's password + sa.getUserPassword( + "jid@example.org", + function(err){ /*...*/ } + ); + // delete a user sa.deleteUser( "jid@example.org", diff --git a/package.json b/package.json index 3fdaa6b..c2bc824 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ ], "engine": "node", "dependencies": { - "node-xmpp-core": "~0.4.9" + "node-xmpp-core": "~0.4.10" }, "devDependencies": { "chai": "~1.9.0", diff --git a/spec/node-xmpp-serviceadmin.spec.coffee b/spec/node-xmpp-serviceadmin.spec.coffee index 6d7ae5b..0950376 100644 --- a/spec/node-xmpp-serviceadmin.spec.coffee +++ b/spec/node-xmpp-serviceadmin.spec.coffee @@ -98,6 +98,35 @@ describe "The Service Admin", -> @admin.changeUserPassword "b@r/t", "new", -> + describe "'getUserPassword' method", -> + + it "takes the JID and a callback as parameters", (done) -> + + xmppClient.onData = (x) -> + + s = new xmpp.Stanza.Iq {type: 'result', id: x.attrs.id} + s.c("command", status: "completed") + .c("x",{type: 'result'}) + .c("field", type: "hidden", var:"FORM_TYPE") + .c("value") + .t("http://jabber.org/protocol/admin") + .up() + .up() + .c("field", var:"accountjid") + .c("value") + .t("b@r/t") + .up() + .c("field", var:"password") + .c("value") + .t("topSecret") + .up() + xmppClient.send s + + @admin.getUserPassword "b@r/t", (err, pw) -> + should.not.exist err + pw.toString().should.equal "topSecret" + done() + describe "'fillForm' helper method", -> it "takes the request stanza and converts is to a response stanza", -> diff --git a/src/ServiceAdmin.coffee b/src/ServiceAdmin.coffee index e7c4a96..5535ea5 100644 --- a/src/ServiceAdmin.coffee +++ b/src/ServiceAdmin.coffee @@ -19,7 +19,7 @@ class ServiceAdmin constructor: (@jid, @comp, @service) -> - runOneStageCmd: (cmd, fields, next) -> + runOneStageCmd: (cmd, fields, next=->) -> id = "exec#{(new Date).getTime()}" comp = @comp @@ -29,7 +29,7 @@ class ServiceAdmin if stanza.attrs.type is 'error' comp.removeListener "stanza", handler - next? new Error "could not execute command" + next new Error "could not execute command" else if stanza.attrs.type is 'result' @@ -42,9 +42,9 @@ class ServiceAdmin when 'completed' comp.removeListener "stanza", handler - if (n = c.getChild "note").attrs?.type is "error" + if (n = c.getChild "note")?.attrs?.type is "error" next new Error n.children?[0] - else next?() + else next undefined, c @comp.on 'stanza', handler cmdIq = ServiceAdmin.createCmdIq @jid, @service, id, cmd @@ -105,4 +105,13 @@ class ServiceAdmin data[PASS] = pw @runOneStageCmd "change-user-password", data, next + getUserPassword: (jid, next) -> + data = {} + data[JID] = ServiceAdmin.getJID jid + @runOneStageCmd "get-user-password", data, (err, c) -> + return next err if err + next undefined, c.getChildByAttr("var", "password", null, true)?. + getChild("value")?. + getText() + module.exports = ServiceAdmin