# HG changeset patch # User souliane # Date 1457695893 -3600 # Node ID 0b748ad46ede3b55cc3f13674fa934872eff757b # Parent 58f25b2745363efaa45dcf7824701e06ae009dcd 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) diff -r 58f25b274536 -r 0b748ad46ede src/plugins/plugin_misc_account.py --- a/src/plugins/plugin_misc_account.py Thu Mar 10 19:13:42 2016 +0100 +++ b/src/plugins/plugin_misc_account.py Fri Mar 11 12:31:33 2016 +0100 @@ -210,9 +210,24 @@ return self.registerAccount(email, password, None, profile) def registerAccount(self, email, password, jid_s, profile): + """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 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: @@ -228,13 +243,12 @@ 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 @@ 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 @@ 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 @@ 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