diff src/plugins/plugin_misc_account.py @ 1729:9037161e28f0

plugin misc_account: send email to the admins when a new profile is created for an external XMPP account
author souliane <souliane@mailoo.org>
date Wed, 09 Dec 2015 01:59:15 +0100
parents 68e498b3367e
children b9493cb6ce49
line wrap: on
line diff
--- a/src/plugins/plugin_misc_account.py	Tue Dec 08 17:41:34 2015 +0100
+++ b/src/plugins/plugin_misc_account.py	Wed Dec 09 01:59:15 2015 +0100
@@ -209,8 +209,8 @@
         else:
             d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile)
             jid_s = "%s@%s" % (profile, self.getConfig('new_account_domain'))
-        if email:
-            d.addCallback(lambda dummy: self.sendEmails(email, jid_s, password, profile))
+
+        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)
@@ -242,6 +242,19 @@
             # TODO: return error code to user
             log.error(u"Failed to send email to %s" % email)
 
+        # email to the administrator
+        body = (u"""New account created: %(profile)s [%(email)s]""" % {'profile': profile, 'email': email}).encode('utf-8')
+        msg = MIMEText(body, 'plain', 'UTF-8')
+        msg['Subject'] = _('New Libervia account created')
+        msg['From'] = _email_from
+        msg['To'] = self.getConfig('admin_email')
+
+        d_admin = sendmail(_email_host, _email_from, self.getConfig('admin_email'), msg.as_string())
+        d_admin.addCallbacks(email_ok, email_ko)
+
+        if not email:
+            return d_admin
+
         body = (_(u"""Welcome to Libervia, the web interface of Salut à Toi.
 
 Your account on %(domain)s has been successfully created. This is a demonstration version to show you the current status of the project. It is still under development, it misses some features and it's not stable enough to be used for any serious purpose. Please keep it in mind!
@@ -272,15 +285,6 @@
         d_user = sendmail(_email_host, _email_from, email, msg.as_string())
         d_user.addCallbacks(email_ok, email_ko)
 
-        # email to the administrator
-        body = (u"""New account created: %(profile)s [%(email)s]""" % {'profile': profile, 'email': email}).encode('utf-8')
-        msg = MIMEText(body, 'plain', 'UTF-8')
-        msg['Subject'] = _('New Libervia account created')
-        msg['From'] = _email_from
-        msg['To'] = self.getConfig('admin_email')
-
-        d_admin = sendmail(_email_host, _email_from, self.getConfig('admin_email'), msg.as_string())
-        d_admin.addCallbacks(email_ok, email_ko)
         return defer.DeferredList([d_user, d_admin])
 
     def getNewAccountDomain(self):