changeset 1080:f25ec9fd7cc4

plugin misc_account: suppress the profile after its creation if the XMPP account registration failed
author souliane <souliane@mailoo.org>
date Thu, 19 Jun 2014 19:20:52 +0200
parents c0ef97002ef4
children 5d89fecdf667
files src/plugins/plugin_misc_account.py
diffstat 1 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_account.py	Wed Jun 18 16:35:20 2014 +0200
+++ b/src/plugins/plugin_misc_account.py	Thu Jun 19 19:20:52 2014 +0200
@@ -174,7 +174,7 @@
         return d
 
     def _profileRegistered(self, result, email, password, profile):
-        """Create the profile and the XMPP account.
+        """Create the XMPP account and send the confirmation email.
 
         @param result: result of asyncCreateProfile
         @param email: user email
@@ -182,20 +182,27 @@
         @param profile: %(doc_profile)s
         @return: a deferred None value when all the processing is done
         """
-        #FIXME: values must be in a config file instead of hardcoded
-        self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, self.getConfig('new_account_domain'), self.getConfig('new_account_resource')),
-                                  "Connection", profile_key=profile)
-        self.host.memory.setParam("Server", self.getConfig('new_account_server'),
-                                  "Connection", profile_key=profile)
-        self.host.memory.setParam("Password", password,
-                                  "Connection", profile_key=profile)
-        #and the account
-
         # XXX: we use "prosodyctl adduser" because "register" doesn't check conflict
         #      and just change the password if the account already exists
         d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile)
         d.addCallback(self._sendEmails, profile, email, password)
         d.addCallback(lambda ignore: None)
+
+        def setParams(dummy):
+            #FIXME: values must be in a config file instead of hardcoded
+            self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, self.getConfig('new_account_domain'), self.getConfig('new_account_resource')),
+                                      "Connection", profile_key=profile)
+            self.host.memory.setParam("Server", self.getConfig('new_account_server'),
+                                      "Connection", profile_key=profile)
+            self.host.memory.setParam("Password", password,
+                                      "Connection", profile_key=profile)
+
+        def removeProfile(failure):
+            self.host.memory.asyncDeleteProfile(profile)
+            return failure
+
+        d.addCallback(setParams)
+        d.addErrback(removeProfile)
         return d
 
     def _sendEmails(self, result, login, email, password):