plugin xep-0045: ask for password when getting a "not-allowed" error
This commit is contained in:
parent
25bbaa705a
commit
71a2fe4599
1 changed files with 22 additions and 4 deletions
|
|
@ -23,6 +23,7 @@ from sat.core.log import getLogger
|
|||
log = getLogger(__name__)
|
||||
from twisted.internet import defer
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.python import failure
|
||||
from dateutil.tz import tzutc
|
||||
|
||||
from sat.core import exceptions
|
||||
|
|
@ -40,7 +41,7 @@ from zope.interface import implements
|
|||
|
||||
|
||||
PLUGIN_INFO = {
|
||||
"name": "XEP 0045 Plugin",
|
||||
"name": "XEP-0045 Plugin",
|
||||
"import_name": "XEP-0045",
|
||||
"type": "XEP",
|
||||
"protocols": ["XEP-0045"],
|
||||
|
|
@ -136,7 +137,15 @@ class XEP_0045(object):
|
|||
else:
|
||||
return True
|
||||
|
||||
def _joinCb(self, room, client):
|
||||
def _passwordUICb(self, data, client, room_jid, nick):
|
||||
"""Called when the user has given room password (or cancelled)"""
|
||||
if C.bool(data.get(C.XMLUI_DATA_CANCELLED, "false")):
|
||||
log.info(u"room join for {} is cancelled".format(room_jid.userhost()))
|
||||
raise failure.Failure(exceptions.CancelError(D_(u"Room joining cancelled by user")))
|
||||
password = data[xml_tools.formEscape('password')]
|
||||
return client._muc_client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, (client, room_jid, nick), errbackArgs=(client, room_jid, nick, password))
|
||||
|
||||
def _joinCb(self, room, client, room_jid, nick):
|
||||
"""Called when the user is in the requested room"""
|
||||
if room.locked:
|
||||
# FIXME: the current behaviour is to create an instant room
|
||||
|
|
@ -157,7 +166,16 @@ class XEP_0045(object):
|
|||
if condition == 'conflict':
|
||||
# we have a nickname conflict, we try again with "_" suffixed to current nickname
|
||||
nick += '_'
|
||||
return client._muc_client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, callbackKeywords={client: client}, errbackArgs=[client, room_jid, nick, password])
|
||||
return client._muc_client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, (client, room_jid, nick), errbackArgs=(client, room_jid, nick, password))
|
||||
elif condition == 'not-allowed':
|
||||
# room is restricted, we need a password
|
||||
password_ui = xml_tools.XMLUI("form", title=D_(u'Room {} is restricted').format(room_jid.userhost()), submit_id='')
|
||||
password_ui.addText(D_("This room is restricted, please enter the password"))
|
||||
password_ui.addPassword('password')
|
||||
d = xml_tools.deferXMLUI(self.host, password_ui, profile=client.profile)
|
||||
d.addCallback(self._passwordUICb, client, room_jid, nick)
|
||||
return d
|
||||
|
||||
msg_suffix = ' with condition "{}"'.format(failure.value.condition)
|
||||
|
||||
mess = D_(u"Error while joining the room {room}{suffix}".format(
|
||||
|
|
@ -387,7 +405,7 @@ class XEP_0045(object):
|
|||
|
||||
password = options["password"] if "password" in options else None
|
||||
|
||||
return client._muc_client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, callbackKeywords={'client': client}, errbackArgs=[client, room_jid, nick, password])
|
||||
return client._muc_client.join(room_jid, nick, password).addCallbacks(self._joinCb, self._joinEb, (client, room_jid, nick), errbackArgs=(client, room_jid, nick, password))
|
||||
|
||||
def _nick(self, room_jid_s, nick, profile_key=C.PROF_KEY_NONE):
|
||||
client = self.host.getClient(profile_key)
|
||||
|
|
|
|||
Loading…
Reference in a new issue