From a8a58cb01abd18551fd2734ace04daeb48f956c5 Mon Sep 17 00:00:00 2001 From: souliane Date: Wed, 9 Dec 2015 01:59:15 +0100 Subject: [PATCH] plugin misc_account: send email to the admins when a new profile is created for an external XMPP account --- src/plugins/plugin_misc_account.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/plugins/plugin_misc_account.py b/src/plugins/plugin_misc_account.py index 9ab7a99a..a72f8f50 100755 --- a/src/plugins/plugin_misc_account.py +++ b/src/plugins/plugin_misc_account.py @@ -209,8 +209,8 @@ class MiscAccount(object): 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 @@ class MiscAccount(object): # 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 @@ http://www.salut-a-toi.org 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):