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
|
||||
is_form = data[2]
|
||||
conf = data[1]
|
||||
helpers.replace_dataform_media(conf, data[4])
|
||||
if self.new_account_form:
|
||||
def _on_register_result(result):
|
||||
if not common.xmpp.isResultNode(result):
|
||||
|
|
|
@ -1598,23 +1598,11 @@ ConnectionJingle, ConnectionIBBytestream):
|
|||
captcha = msg.getTag('captcha', namespace=common.xmpp.NS_CAPTCHA)
|
||||
if captcha:
|
||||
captcha = captcha.getTag('x', namespace=common.xmpp.NS_DATA)
|
||||
for field in captcha.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 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
|
||||
found = helpers.replace_dataform_media(captcha, msg)
|
||||
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,
|
||||
msg.getXHTML(), statusCode, displaymarking, captcha))
|
||||
|
||||
|
|
|
@ -1355,3 +1355,18 @@ def get_subscription_request_msg(account=None):
|
|||
name = nick
|
||||
s = Template(s).safe_substitute({'name': name})
|
||||
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)
|
||||
if not isResultNode(resp):
|
||||
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
|
||||
tag=resp.getTag('query', namespace=NS_REGISTER)
|
||||
if not tag:
|
||||
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
|
||||
df=tag.getTag('x', namespace=NS_DATA)
|
||||
if df:
|
||||
con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, df, True, ''))
|
||||
con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, df, True, '',
|
||||
tag))
|
||||
return
|
||||
df={}
|
||||
for i in resp.getQueryPayload():
|
||||
if not isinstance(i, Node):
|
||||
continue
|
||||
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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue