Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
added 'getUserPassword' method
Browse files Browse the repository at this point in the history
  • Loading branch information
flosse committed Feb 7, 2014
1 parent 5d1e1f7 commit bfad357
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.markdown
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -21,7 +21,7 @@
],
"engine": "node",
"dependencies": {
"node-xmpp-core": "~0.4.9"
"node-xmpp-core": "~0.4.10"
},
"devDependencies": {
"chai": "~1.9.0",
Expand Down
29 changes: 29 additions & 0 deletions spec/node-xmpp-serviceadmin.spec.coffee
Expand Up @@ -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", ->
Expand Down
17 changes: 13 additions & 4 deletions src/ServiceAdmin.coffee
Expand Up @@ -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
Expand All @@ -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'

Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit bfad357

Please sign in to comment.