comparison 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
comparison
equal deleted inserted replaced
1728:0eaa1a409dfb 1729:9037161e28f0
207 if jid_s: 207 if jid_s:
208 d = defer.succeed(None) 208 d = defer.succeed(None)
209 else: 209 else:
210 d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile) 210 d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile)
211 jid_s = "%s@%s" % (profile, self.getConfig('new_account_domain')) 211 jid_s = "%s@%s" % (profile, self.getConfig('new_account_domain'))
212 if email: 212
213 d.addCallback(lambda dummy: self.sendEmails(email, jid_s, password, profile)) 213 d.addCallback(lambda dummy: self.sendEmails(email, jid_s, password, profile))
214 214
215 def setParams(dummy): 215 def setParams(dummy):
216 self.host.memory.setParam("JabberID", jid_s, "Connection", profile_key=profile) 216 self.host.memory.setParam("JabberID", jid_s, "Connection", profile_key=profile)
217 d = self.host.memory.setParam("Password", password, "Connection", profile_key=profile) 217 d = self.host.memory.setParam("Password", password, "Connection", profile_key=profile)
218 return d 218 return d
239 log.debug(u"Account creation email sent to %s" % email) 239 log.debug(u"Account creation email sent to %s" % email)
240 240
241 def email_ko(ignore): 241 def email_ko(ignore):
242 # TODO: return error code to user 242 # TODO: return error code to user
243 log.error(u"Failed to send email to %s" % email) 243 log.error(u"Failed to send email to %s" % email)
244
245 # email to the administrator
246 body = (u"""New account created: %(profile)s [%(email)s]""" % {'profile': profile, 'email': email}).encode('utf-8')
247 msg = MIMEText(body, 'plain', 'UTF-8')
248 msg['Subject'] = _('New Libervia account created')
249 msg['From'] = _email_from
250 msg['To'] = self.getConfig('admin_email')
251
252 d_admin = sendmail(_email_host, _email_from, self.getConfig('admin_email'), msg.as_string())
253 d_admin.addCallbacks(email_ok, email_ko)
254
255 if not email:
256 return d_admin
244 257
245 body = (_(u"""Welcome to Libervia, the web interface of Salut à Toi. 258 body = (_(u"""Welcome to Libervia, the web interface of Salut à Toi.
246 259
247 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! 260 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!
248 261
270 msg['To'] = email 283 msg['To'] = email
271 284
272 d_user = sendmail(_email_host, _email_from, email, msg.as_string()) 285 d_user = sendmail(_email_host, _email_from, email, msg.as_string())
273 d_user.addCallbacks(email_ok, email_ko) 286 d_user.addCallbacks(email_ok, email_ko)
274 287
275 # email to the administrator
276 body = (u"""New account created: %(profile)s [%(email)s]""" % {'profile': profile, 'email': email}).encode('utf-8')
277 msg = MIMEText(body, 'plain', 'UTF-8')
278 msg['Subject'] = _('New Libervia account created')
279 msg['From'] = _email_from
280 msg['To'] = self.getConfig('admin_email')
281
282 d_admin = sendmail(_email_host, _email_from, self.getConfig('admin_email'), msg.as_string())
283 d_admin.addCallbacks(email_ok, email_ko)
284 return defer.DeferredList([d_user, d_admin]) 288 return defer.DeferredList([d_user, d_admin])
285 289
286 def getNewAccountDomain(self): 290 def getNewAccountDomain(self):
287 """@return: the domain that will be set to new account""" 291 """@return: the domain that will be set to new account"""
288 return self.getConfig('new_account_domain') 292 return self.getConfig('new_account_domain')