Mercurial > libervia-backend
comparison src/plugins/plugin_misc_account.py @ 1765:b9493cb6ce49
plugin misc_account: fixes login messages when sending emails
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 22 Dec 2015 16:20:25 +0100 |
parents | 9037161e28f0 |
children | d17772b0fe22 |
comparison
equal
deleted
inserted
replaced
1764:33c815c17fe6 | 1765:b9493cb6ce49 |
---|---|
228 return d | 228 return d |
229 | 229 |
230 def sendEmails(self, email, jid_s, password, profile): | 230 def sendEmails(self, email, jid_s, password, profile): |
231 # time to send the email | 231 # time to send the email |
232 | 232 |
233 _email_host = self.getConfig('email_server') | 233 email_host = self.getConfig('email_server') |
234 _email_from = self.getConfig("email_from") | 234 email_from = self.getConfig("email_from") |
235 domain = self.getConfig('new_account_domain') | 235 domain = self.getConfig('new_account_domain') |
236 | |
237 | |
238 def email_ok(ignore): | |
239 log.debug(u"Account creation email sent to %s" % email) | |
240 | |
241 def email_ko(ignore): | |
242 # TODO: return error code to user | |
243 log.error(u"Failed to send email to %s" % email) | |
244 | 236 |
245 # email to the administrator | 237 # email to the administrator |
246 body = (u"""New account created: %(profile)s [%(email)s]""" % {'profile': profile, 'email': email}).encode('utf-8') | 238 body = (u"""New account created: %(profile)s [%(email)s]""" % {'profile': profile, 'email': email}).encode('utf-8') |
247 msg = MIMEText(body, 'plain', 'UTF-8') | 239 msg = MIMEText(body, 'plain', 'UTF-8') |
248 msg['Subject'] = _('New Libervia account created') | 240 msg['Subject'] = _('New Libervia account created') |
249 msg['From'] = _email_from | 241 msg['From'] = email_from |
250 msg['To'] = self.getConfig('admin_email') | 242 msg['To'] = self.getConfig('admin_email') |
251 | 243 |
252 d_admin = sendmail(_email_host, _email_from, self.getConfig('admin_email'), msg.as_string()) | 244 admin_email = self.getConfig('admin_email') |
253 d_admin.addCallbacks(email_ok, email_ko) | 245 d_admin = sendmail(email_host, email_from, admin_email, msg.as_string()) |
254 | 246 d_admin.addCallbacks(lambda dummy: log.debug(u"Account creation notification sent to admin <%s>" % admin_email), |
247 lambda dummy: log.error(u"Failed to send account creation notification to admin <%s>" % admin_email)) | |
255 if not email: | 248 if not email: |
256 return d_admin | 249 return d_admin |
257 | 250 |
258 body = (_(u"""Welcome to Libervia, the web interface of Salut à Toi. | 251 body = (_(u"""Welcome to Libervia, the web interface of Salut à Toi. |
259 | 252 |
277 Salut à Toi association | 270 Salut à Toi association |
278 http://www.salut-a-toi.org | 271 http://www.salut-a-toi.org |
279 """) % {'profile': profile, 'jid_s': jid_s, 'domain': domain}).encode('utf-8') | 272 """) % {'profile': profile, 'jid_s': jid_s, 'domain': domain}).encode('utf-8') |
280 msg = MIMEText(body, 'plain', 'UTF-8') | 273 msg = MIMEText(body, 'plain', 'UTF-8') |
281 msg['Subject'] = _(u'Libervia account created') | 274 msg['Subject'] = _(u'Libervia account created') |
282 msg['From'] = _email_from | 275 msg['From'] = email_from |
283 msg['To'] = email | 276 msg['To'] = email |
284 | 277 |
285 d_user = sendmail(_email_host, _email_from, email, msg.as_string()) | 278 def email_ko(dummy): |
286 d_user.addCallbacks(email_ok, email_ko) | 279 # TODO: return error code to user |
287 | 280 log.error(u"Failed to send account creation confirmation to <%s>" % email) |
281 | |
282 d_user = sendmail(email_host, email_from, email, msg.as_string()) | |
283 d_user.addCallbacks(lambda dummy: log.debug(u"Account creation confirmation sent to <%s>" % email), | |
284 email_ko) | |
288 return defer.DeferredList([d_user, d_admin]) | 285 return defer.DeferredList([d_user, d_admin]) |
289 | 286 |
290 def getNewAccountDomain(self): | 287 def getNewAccountDomain(self): |
291 """@return: the domain that will be set to new account""" | 288 """@return: the domain that will be set to new account""" |
292 return self.getConfig('new_account_domain') | 289 return self.getConfig('new_account_domain') |