1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """In-band registration (jabber:iq:register) handling.
19
20 Normative reference:
21 - `JEP 77 <http://www.jabber.org/jeps/jep-0077.html>`__
22 """
23
24 __docformat__="restructuredtext en"
25
26 import libxml2
27 import logging
28
29 from pyxmpp.utils import to_utf8,from_utf8
30 from pyxmpp.xmlextra import get_node_ns_uri
31 from pyxmpp.objects import StanzaPayloadObject
32 from pyxmpp.xmlextra import xml_element_iter
33
34 from pyxmpp.jabber.dataforms import DATAFORM_NS, Form
35
36 REGISTER_NS="jabber:iq:register"
37
38 legacy_fields = {
39 "username": ("text-single", u"Account name associated with the user"),
40 "nick": ("text-single", u"Familiar name of the user"),
41 "password": ("text-private", u"Password or secret for the user"),
42 "name": ("text-single", u"Full name of the user"),
43 "first": ("text-single", u"First name or given name of the user"),
44 "last": ("text-single", u"Last name, surname, or family name of the user"),
45 "email": ("text-single", u"Email address of the user"),
46 "address": ("text-single", u"Street portion of a physical or mailing address"),
47 "city": ("text-single", u"Locality portion of a physical or mailing address"),
48 "state": ("text-single", u"Region portion of a physical or mailing address"),
49 "zip": ("text-single", u"Postal code portion of a physical or mailing address"),
50 "phone": ("text-single", u"Telephone number of the user"),
51 "url": ("text-single", u"URL to web page describing the user"),
52 "date": ("text-single", u"Some date (e.g., birth date, hire date, sign-up date)"),
53 "misc": ("text-single", u"Free-form text field (obsolete)"),
54 "text": ("text-single", u"Free-form text field (obsolete)"),
55 "key": ("text-single", u"Session key for transaction (obsolete)"),
56 }
57
59 """
60 Delayed delivery tag.
61
62 Represents 'jabber:iq:register' (JEP-0077) element of a Jabber <iq/> stanza.
63
64 Please note that it is recommended to use `get_form` and `submit_form` records
65 instead of accessing the `form` and legacy fields directly. This way both
66 legacy and Data Forms registration would work transparently to the application.
67
68 :Ivariables:
69 - `form`: registration form (when available)
70 - `registered`: `True` if entity is already registered
71 - `instrutions`: Registration instructions (legacy protocol)
72 - `username`: Username field (legacy protocol)
73 - `nick`: Nickname (legacy protocol)
74 - `password`: Password (legacy protocol)
75 - `name`: Name field (legacy protocol)
76 - `first`: First name field (legacy protocol)
77 - `last`: Last name field (legacy protocol)
78 - `email`: E-mail field (legacy protocol)
79 - `address`: Address field (legacy protocol)
80 - `city`: City field (legacy protocol)
81 - `state`: State field (legacy protocol)
82 - `zip`: ZIP code field (legacy protocol)
83 - `phone`: Phone field (legacy protocol)
84 - `url`: URL field (legacy protocol)
85 - `date`: Date field (legacy protocol)
86 - `misc`: Misc field (legacy protocol, obsolete)
87 - `text`: Text field (legacy protocol, obsolete)
88 - `key`: Key field (legacy protocol, obsolete)
89 - `remove`: `True` when the account should be removed
90 :Types:
91 - `form`: `pyxmpp.jabber.dataforms.Form`
92 - `registered`: `bool`
93 - `instrutions`: `unicode`
94 - `username`: `unicode`
95 - `nick`: `unicode`
96 - `password`: `unicode`
97 - `name`: `unicode`
98 - `first`: `unicode`
99 - `last`: `unicode`
100 - `email`: `unicode`
101 - `address`: `unicode`
102 - `city`: `unicode`
103 - `state`: `unicode`
104 - `zip`: `unicode`
105 - `phone`: `unicode`
106 - `url`: `unicode`
107 - `date`: `unicode`
108 - `misc`: `unicode`
109 - `text`: `unicode`
110 - `key`: `unicode`
111 - `remove`: `True` when the account should be removed
112 """
113
114 xml_element_name = "query"
115 xml_element_namespace = REGISTER_NS
116
118 """
119 Initialize the `Register` object.
120
121 :Parameters:
122 - `xmlnode`: an optional XML node to parse.
123 :Types:
124 - `xmlnode`: `libxml2.xmlNode`
125 """
126 self.__logger=logging.getLogger("pyxmpp.jabber.Register")
127 self.form = None
128 self.registered = False
129 self.instructions = None
130 self.remove = False
131 for f in legacy_fields:
132 setattr(self, f, None)
133 if isinstance(xmlnode,libxml2.xmlNode):
134 self.__from_xml(xmlnode)
135
170
172 """Complete the XML node with `self` content.
173
174 :Parameters:
175 - `xmlnode`: XML node with the element being built. It has already
176 right name and namespace, but no attributes or content.
177 - `doc`: document to which the element belongs.
178 :Types:
179 - `xmlnode`: `libxml2.xmlNode`
180 - `doc`: `libxml2.xmlDoc`"""
181 ns = xmlnode.ns()
182 if self.instructions is not None:
183 xmlnode.newTextChild(ns, "instructions", to_utf8(self.instructions))
184 if self.form:
185 self.form.as_xml(xmlnode, doc)
186 if self.remove:
187 xmlnode.newChild(ns, "remove", None)
188 else:
189 if self.registered:
190 xmlnode.newChild(ns, "registered", None)
191 for field in legacy_fields:
192 value = getattr(self, field)
193 if value is not None:
194 xmlnode.newTextChild(ns, field, to_utf8(value))
195
230
264
265
266
267