handle captcha images when registering an account
This commit is contained in:
parent
26d6b50e3e
commit
1048db503e
|
@ -824,6 +824,7 @@ class Connection(CommonConnection, ConnectionHandlers):
|
||||||
return
|
return
|
||||||
is_form = data[2]
|
is_form = data[2]
|
||||||
conf = data[1]
|
conf = data[1]
|
||||||
|
helpers.replace_dataform_media(conf, data[4])
|
||||||
if self.new_account_form:
|
if self.new_account_form:
|
||||||
def _on_register_result(result):
|
def _on_register_result(result):
|
||||||
if not common.xmpp.isResultNode(result):
|
if not common.xmpp.isResultNode(result):
|
||||||
|
|
|
@ -1598,23 +1598,11 @@ ConnectionJingle, ConnectionIBBytestream):
|
||||||
captcha = msg.getTag('captcha', namespace=common.xmpp.NS_CAPTCHA)
|
captcha = msg.getTag('captcha', namespace=common.xmpp.NS_CAPTCHA)
|
||||||
if captcha:
|
if captcha:
|
||||||
captcha = captcha.getTag('x', namespace=common.xmpp.NS_DATA)
|
captcha = captcha.getTag('x', namespace=common.xmpp.NS_DATA)
|
||||||
for field in captcha.getTags('field'):
|
found = helpers.replace_dataform_media(captcha, msg)
|
||||||
for media in field.getTags('media'):
|
if not found:
|
||||||
for uri in media.getTags('uri'):
|
self.get_bob_data(uri_data, frm, self.dispatch_gc_message,
|
||||||
uri_data = uri.getData()
|
[msg, frm, msgtxt, jid, tim], 0)
|
||||||
if uri_data.startswith('cid:'):
|
return
|
||||||
uri_data = uri_data[4:]
|
|
||||||
found = False
|
|
||||||
for data in msg.getTags('data',
|
|
||||||
namespace=common.xmpp.NS_BOB):
|
|
||||||
if data.getAttr('cid') == uri_data:
|
|
||||||
uri.setData(data.getData())
|
|
||||||
found = True
|
|
||||||
if not found:
|
|
||||||
self.get_bob_data(uri_data, frm,
|
|
||||||
self.dispatch_gc_message, [msg, frm, msgtxt,
|
|
||||||
jid, tim], 0)
|
|
||||||
return
|
|
||||||
self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp,
|
self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp,
|
||||||
msg.getXHTML(), statusCode, displaymarking, captcha))
|
msg.getXHTML(), statusCode, displaymarking, captcha))
|
||||||
|
|
||||||
|
|
|
@ -1355,3 +1355,18 @@ def get_subscription_request_msg(account=None):
|
||||||
name = nick
|
name = nick
|
||||||
s = Template(s).safe_substitute({'name': name})
|
s = Template(s).safe_substitute({'name': name})
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
def replace_dataform_media(form, stanza):
|
||||||
|
import xmpp
|
||||||
|
for field in form.getTags('field'):
|
||||||
|
for media in field.getTags('media'):
|
||||||
|
for uri in media.getTags('uri'):
|
||||||
|
uri_data = uri.getData()
|
||||||
|
if uri_data.startswith('cid:'):
|
||||||
|
uri_data = uri_data[4:]
|
||||||
|
found = False
|
||||||
|
for data in stanza.getTags('data', namespace=xmpp.NS_BOB):
|
||||||
|
if data.getAttr('cid') == uri_data:
|
||||||
|
uri.setData(data.getData())
|
||||||
|
found = True
|
||||||
|
return found
|
|
@ -58,23 +58,24 @@ def _ReceivedRegInfo(con, resp, agent):
|
||||||
Iq('get', NS_REGISTER, to=agent)
|
Iq('get', NS_REGISTER, to=agent)
|
||||||
if not isResultNode(resp):
|
if not isResultNode(resp):
|
||||||
error_msg = resp.getErrorMsg()
|
error_msg = resp.getErrorMsg()
|
||||||
con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, None, False, error_msg))
|
con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, None, False, error_msg, ''))
|
||||||
return
|
return
|
||||||
tag=resp.getTag('query', namespace=NS_REGISTER)
|
tag=resp.getTag('query', namespace=NS_REGISTER)
|
||||||
if not tag:
|
if not tag:
|
||||||
error_msg = resp.getErrorMsg()
|
error_msg = resp.getErrorMsg()
|
||||||
con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, None, False, error_msg))
|
con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, None, False, error_msg, ''))
|
||||||
return
|
return
|
||||||
df=tag.getTag('x', namespace=NS_DATA)
|
df=tag.getTag('x', namespace=NS_DATA)
|
||||||
if df:
|
if df:
|
||||||
con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, df, True, ''))
|
con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, df, True, '',
|
||||||
|
tag))
|
||||||
return
|
return
|
||||||
df={}
|
df={}
|
||||||
for i in resp.getQueryPayload():
|
for i in resp.getQueryPayload():
|
||||||
if not isinstance(i, Node):
|
if not isinstance(i, Node):
|
||||||
continue
|
continue
|
||||||
df[i.getName()] = i.getData()
|
df[i.getName()] = i.getData()
|
||||||
con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, df, False, ''))
|
con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, df, False, '', ''))
|
||||||
|
|
||||||
def register(disp, host, info, cb, args=None):
|
def register(disp, host, info, cb, args=None):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue