plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)

This commit is contained in:
souliane 2016-03-11 12:31:33 +01:00
commit ba1e8079ed

View file

@ -210,9 +210,24 @@ class MiscAccount(object):
return self.registerAccount(email, password, None, profile)
def registerAccount(self, email, password, jid_s, profile):
"""Register a new profile and its associated XMPP account.
"""Register a new profile, its associated XMPP account, send the confirmation emails.
@param email (unicode): where to send to confirmation email to
@param password (unicode): password chosen by the user
while be used for profile *and* XMPP account
@param jid_s (unicode): JID to re-use or to register:
- non empty value: bind this JID to the new sat profile
- None or "": register a new JID on the local XMPP server
@param profile
@return Deferred
"""
d = self.createProfile(password, jid_s, profile)
d.addCallback(lambda dummy: self.sendEmails(email, jid_s, password, profile))
return d
def createProfile(self, password, jid_s, profile):
"""Register a new profile and its associated XMPP account.
@param password (unicode): password chosen by the user
while be used for profile *and* XMPP account
@param jid_s (unicode): JID to re-use or to register:
@ -228,13 +243,12 @@ class MiscAccount(object):
return defer.fail(Failure(exceptions.ConflictError))
d = self.host.memory.asyncCreateProfile(profile, password)
d.addCallback(lambda dummy: self.profileRegistered(email, password, jid_s, profile))
d.addCallback(lambda dummy: self.profileCreated(password, jid_s, profile))
return d
def profileRegistered(self, email, password, jid_s, profile):
"""Create the XMPP account, set the profile connection parameters and send the confirmation email.
def profileCreated(self, password, jid_s, profile):
"""Create the XMPP account and set the profile connection parameters.
@param email (unicode): where to send to confirmation email to
@param password (unicode): password chosen by the user
@param jid_s (unicode): JID to re-use or to register:
- non empty value: bind this JID to the new sat profile
@ -249,8 +263,6 @@ class MiscAccount(object):
d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile)
jid_s = "%s@%s" % (profile, self.getConfig('new_account_domain'))
d.addCallback(lambda dummy: self.sendEmails(email, jid_s, password, profile))
def setParams(dummy):
self.host.memory.setParam("JabberID", jid_s, "Connection", profile_key=profile)
d = self.host.memory.setParam("Password", password, "Connection", profile_key=profile)
@ -602,7 +614,7 @@ http://www.salut-a-toi.org
else:
raise exceptions.ConflictError
d = self.registerAccount(None, password, jid_s, jid_s)
d = self.createProfile(password, jid_s, jid_s)
d.addCallback(lambda dummy: self.host.memory.getProfileName(jid_s)) # checks if the profile has been successfuly created
d.addCallback(self.host.asyncConnect, password, 0)
@ -611,5 +623,8 @@ http://www.salut-a-toi.org
self.host.memory.asyncDeleteProfile(jid_s)
raise failure
d.addErrback(removeProfile)
# FIXME: we don't catch the case where the JID host is not an XMPP server, and the user
# has to wait until the DBUS timeout ; as a consequence, emails are sent to the admins
# and the profile is not deleted. When the host exists, removeProfile is well called.
d.addCallbacks(lambda dummy: self.sendEmails(None, jid_s, password, jid_s), removeProfile)
return d