Mercurial > libervia-backend
changeset 1907:0b748ad46ede
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)
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 11 Mar 2016 12:31:33 +0100 |
parents | 58f25b274536 |
children | ffcd7904b655 |
files | src/plugins/plugin_misc_account.py |
diffstat | 1 files changed, 24 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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