core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
- the bridge method has been removed, now a plugin takes care of it with XMLUI callback system
- TODO: xmpp.RegisteringAuthenticator still needs to be fixed
This commit is contained in:
parent
2a74cd0c06
commit
dd597a2ead
1 changed files with 131 additions and 95 deletions
|
|
@ -17,7 +17,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from sat.core.i18n import _
|
||||
from sat.core.i18n import _, D_
|
||||
from sat.core.constants import Const as C
|
||||
from twisted.internet import task, defer
|
||||
from twisted.words.protocols.jabber import jid, xmlstream
|
||||
|
|
@ -412,20 +412,19 @@ class SatFallbackHandler(generic.FallbackHandler):
|
|||
|
||||
class RegisteringAuthenticator(xmlstream.ConnectAuthenticator):
|
||||
|
||||
def __init__(self, host, jabber_host, user_login, user_pass, email, answer_id, profile):
|
||||
def __init__(self, host, jabber_host, user_login, user_pass, email, deferred, profile):
|
||||
xmlstream.ConnectAuthenticator.__init__(self, jabber_host)
|
||||
self.host = host
|
||||
self.jabber_host = jabber_host
|
||||
self.user_login = user_login
|
||||
self.user_pass = user_pass
|
||||
self.user_email = email
|
||||
self.answer_id = answer_id
|
||||
self.deferred = deferred
|
||||
self.profile = profile
|
||||
print _("Registration asked for"), user_login, user_pass, jabber_host
|
||||
log.debug(_("Registration asked for %(user)s@%(host)s") % {'user': user_login, 'host': jabber_host})
|
||||
|
||||
def connectionMade(self):
|
||||
print "connectionMade"
|
||||
|
||||
log.debug(_("Connection made with %s" % self.jabber_host))
|
||||
self.xmlstream.namespace = "jabber:client"
|
||||
self.xmlstream.sendHeader()
|
||||
|
||||
|
|
@ -439,27 +438,17 @@ class RegisteringAuthenticator(xmlstream.ConnectAuthenticator):
|
|||
if self.user_email:
|
||||
_email = query.addElement('email')
|
||||
_email.addContent(self.user_email)
|
||||
iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure)
|
||||
d = iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure)
|
||||
d.chainDeferred(self.deferred)
|
||||
|
||||
def registrationAnswer(self, answer):
|
||||
log.debug(_("registration answer: %s") % answer.toXml())
|
||||
answer_type = "SUCCESS"
|
||||
answer_data = {"message": _("Registration successfull")}
|
||||
self.host.bridge.actionResult(answer_type, self.answer_id, answer_data, self.profile)
|
||||
log.debug(_("Registration answer: %s") % answer.toXml())
|
||||
self.xmlstream.sendFooter()
|
||||
|
||||
def registrationFailure(self, failure):
|
||||
log.info(_("Registration failure: %s") % str(failure.value))
|
||||
answer_type = "ERROR"
|
||||
answer_data = {}
|
||||
if failure.value.condition == 'conflict':
|
||||
answer_data['reason'] = 'conflict'
|
||||
answer_data = {"message": _("Username already exists, please choose an other one")}
|
||||
else:
|
||||
answer_data['reason'] = 'unknown'
|
||||
answer_data = {"message": _("Registration failed (%s)") % str(failure.value.condition)}
|
||||
self.host.bridge.actionResult(answer_type, self.answer_id, answer_data, self.profile)
|
||||
self.xmlstream.sendFooter()
|
||||
raise failure.value
|
||||
|
||||
|
||||
class SatVersionHandler(generic.VersionHandler):
|
||||
|
|
|
|||
Loading…
Reference in a new issue