/src/legacy/services/ConfirmAccount.py

http://pyaimt.googlecode.com/ · Python · 67 lines · 54 code · 11 blank · 2 comment · 10 complexity · 6b541dc4fd6867462e49e1a22432858f MD5 · raw file

  1. # Copyright 2005-2006 Daniel Henninger <jadestorm@nc.rr.com>
  2. # Licensed for distribution under the GPL version 2, check COPYING for details
  3. import utils
  4. from twisted.words.xish.domish import Element
  5. from twisted.words.protocols.jabber.jid import internJID
  6. from debug import LogEvent, INFO, WARN, ERROR
  7. import config
  8. import lang
  9. import globals
  10. class ConfirmAccount:
  11. def __init__(self, pytrans):
  12. self.pytrans = pytrans
  13. self.pytrans.adhoc.addCommand("confirmaccount", self.incomingIq, "command_ConfirmAccount")
  14. def incomingIq(self, el):
  15. to = el.getAttribute("from")
  16. toj = internJID(to)
  17. ID = el.getAttribute("id")
  18. ulang = utils.getLang(el)
  19. sessionid = None
  20. for command in el.elements():
  21. sessionid = command.getAttribute("sessionid")
  22. if command.getAttribute("action") == "cancel":
  23. self.pytrans.adhoc.sendCancellation("confirmaccount", el, sessionid)
  24. return
  25. if not self.pytrans.sessions.has_key(toj.userhost()) or not hasattr(self.pytrans.sessions[toj.userhost()].legacycon, "bos"):
  26. self.pytrans.adhoc.sendError("confirmaccount", el, errormsg=lang.get("command_NoSession", ulang), sessionid=sessionid)
  27. else:
  28. self.pytrans.sessions[toj.userhost()].legacycon.bos.confirmAccount().addCallback(self.sendResponse, el, sessionid)
  29. def sendResponse(self, failure, el, sessionid=None):
  30. LogEvent(INFO)
  31. to = el.getAttribute("from")
  32. toj = internJID(to)
  33. ID = el.getAttribute("id")
  34. ulang = utils.getLang(el)
  35. iq = Element((None, "iq"))
  36. iq.attributes["to"] = to
  37. iq.attributes["from"] = config.jid
  38. if ID:
  39. iq.attributes["id"] = ID
  40. iq.attributes["type"] = "result"
  41. command = iq.addElement("command")
  42. if sessionid:
  43. command.attributes["sessionid"] = sessionid
  44. else:
  45. command.attributes["sessionid"] = self.pytrans.makeMessageID()
  46. command.attributes["node"] = "confirmaccount"
  47. command.attributes["xmlns"] = globals.COMMANDS
  48. command.attributes["status"] = "completed"
  49. note = command.addElement("note")
  50. if failure:
  51. note.attributes["type"] = "error"
  52. note.addContent(lang.get("command_ConfirmAccount_Failed", ulang))
  53. else:
  54. note.attributes["type"] = "info"
  55. note.addContent(lang.get("command_ConfirmAccount_Complete", ulang))
  56. self.pytrans.send(iq)