Commit f28ff1df authored by Philipp Hörist's avatar Philipp Hörist

Register: Add request_register_form()

parent dab91c3d
......@@ -553,4 +553,21 @@ CHATSTATES = [
\ No newline at end of file
......@@ -17,13 +17,21 @@
import logging
from nbxmpp.protocol import NS_X_OOB
from nbxmpp.protocol import NS_DATA
from nbxmpp.protocol import NS_REGISTER
from nbxmpp.protocol import Iq
from nbxmpp.protocol import isResultNode
from nbxmpp.structs import CommonResult
from nbxmpp.structs import RegisterData
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
from nbxmpp.util import raise_error
from nbxmpp.const import REGISTER_FIELDS
from nbxmpp.modules.bits_of_binary import parse_bob_data
from nbxmpp.modules.dataforms import extend_form
from nbxmpp.modules.dataforms import create_field
from nbxmpp.modules.dataforms import SimpleDataForm
log = logging.getLogger('nbxmpp.m.register')
......@@ -42,8 +50,72 @@ class Register:
return iq
def request_register_form(self, jid=None):
if jid is None:
jid = self._client.Server
return Iq('get', NS_REGISTER, to=jid)
def _on_register_form(self, stanza):
query = stanza.getQuery()
instructions = query.getTagData('instructions') or None
return RegisterData(instructions=instructions,
def _default_response(self, stanza):
if not isResultNode(stanza):
return raise_error(, stanza)
return CommonResult(jid=stanza.getFrom())
def _parse_oob_url(query):
oob = query.getTag('x', namespace=NS_X_OOB)
if oob is not None:
return oob.getTagData('url') or None
return None
def _parse_form(stanza):
form = stanza.getQuery().getTag('x', namespace=NS_DATA)
if form is None:
return None
form = extend_form(node=form)
field = form.vars.get('FORM_TYPE')
if field is None:
log.warning('No FORM_TYPE found')
return None
# Invalid urn:xmpp:captcha used by ejabberd
# See
if field.value in ('jabber:iq:register', 'urn:xmpp:captcha'):
return form
return None
def _parse_fields_form(query):
fields = []
for field in query.getChildren():
field_name = field.getName()
if field_name not in REGISTER_FIELDS:
required = field_name in ('username', 'password')
typ = 'text-single' if field_name != 'password' else 'text-private'
if not fields:
return None
fields.append(create_field(typ='hidden', var='fakeform'))
return SimpleDataForm(type_='form', fields=fields)
......@@ -131,6 +131,8 @@ CorrectionData = namedtuple('CorrectionData', 'id')
DisplayMarking = namedtuple('DisplayMarking', 'label fgcolor bgcolor')
SecurityLabel = namedtuple('SecurityLabel', 'displaymarking')
RegisterData = namedtuple('RegisterData', 'instructions form fields_form oob_url bob_data')
class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms timestamp')):
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment