comparison src/plugins/plugin_misc_account.py @ 1916:72837638f076

plugin misc_account: fixes two bugs introduced by revision 1907 (0b748ad46ede): - the email sent to the user was not displaying its his/her JID - creating an account from an external JID was not returning a bool
author souliane <souliane@mailoo.org>
date Mon, 21 Mar 2016 17:00:39 +0100
parents 0b748ad46ede
children 2daf7b4c6756
comparison
equal deleted inserted replaced
1915:fd959c8f64b6 1916:72837638f076
220 - None or "": register a new JID on the local XMPP server 220 - None or "": register a new JID on the local XMPP server
221 @param profile 221 @param profile
222 @return Deferred 222 @return Deferred
223 """ 223 """
224 d = self.createProfile(password, jid_s, profile) 224 d = self.createProfile(password, jid_s, profile)
225 d.addCallback(lambda dummy: self.sendEmails(email, jid_s, password, profile)) 225 d.addCallback(lambda dummy: self.sendEmails(email, profile))
226 return d 226 return d
227 227
228 def createProfile(self, password, jid_s, profile): 228 def createProfile(self, password, jid_s, profile):
229 """Register a new profile and its associated XMPP account. 229 """Register a new profile and its associated XMPP account.
230 230
276 d.addCallback(setParams) 276 d.addCallback(setParams)
277 d.addCallback(lambda dummy: self.host.memory.stopSession(profile)) 277 d.addCallback(lambda dummy: self.host.memory.stopSession(profile))
278 d.addErrback(removeProfile) 278 d.addErrback(removeProfile)
279 return d 279 return d
280 280
281 def sendEmails(self, email, jid_s, password, profile): 281 def sendEmails(self, email, profile):
282 # time to send the email 282 # time to send the email
283 283
284 email_host = self.getConfig('email_server') 284 email_host = self.getConfig('email_server')
285 email_from = self.getConfig("email_from") 285 email_from = self.getConfig("email_from")
286 email_sender_domain = self.getConfig("email_sender_domain") or None 286 email_sender_domain = self.getConfig("email_sender_domain") or None
320 d_admin.addCallbacks(lambda dummy: log.debug(u"Account creation notification sent to admin(s) {}".format(admins_emails_txt)), 320 d_admin.addCallbacks(lambda dummy: log.debug(u"Account creation notification sent to admin(s) {}".format(admins_emails_txt)),
321 lambda dummy: log.error(u"Failed to send account creation notification to admin {}".format(admins_emails_txt))) 321 lambda dummy: log.error(u"Failed to send account creation notification to admin {}".format(admins_emails_txt)))
322 if not email: 322 if not email:
323 return d_admin 323 return d_admin
324 324
325 jid_s = self.host.memory.getParamA("JabberID", "Connection", profile_key=profile)
325 body = (_(u"""Welcome to Libervia, the web interface of Salut à Toi. 326 body = (_(u"""Welcome to Libervia, the web interface of Salut à Toi.
326 327
327 Your account on {domain} has been successfully created. This is a demonstration version to show you the current status of the project. It is still under development, please keep it in mind! 328 Your account on {domain} has been successfully created. This is a demonstration version to show you the current status of the project. It is still under development, please keep it in mind!
328 329
329 Here is your connection information: 330 Here is your connection information:
616 617
617 d = self.createProfile(password, jid_s, jid_s) 618 d = self.createProfile(password, jid_s, jid_s)
618 d.addCallback(lambda dummy: self.host.memory.getProfileName(jid_s)) # checks if the profile has been successfuly created 619 d.addCallback(lambda dummy: self.host.memory.getProfileName(jid_s)) # checks if the profile has been successfuly created
619 d.addCallback(self.host.asyncConnect, password, 0) 620 d.addCallback(self.host.asyncConnect, password, 0)
620 621
622
623 def connected(result):
624 self.sendEmails(None, profile=jid_s)
625 return result
626
621 def removeProfile(failure): # profile has been successfully created but the XMPP credentials are wrong! 627 def removeProfile(failure): # profile has been successfully created but the XMPP credentials are wrong!
622 log.debug("Removing previously auto-created profile: %s" % failure.getErrorMessage()) 628 log.debug("Removing previously auto-created profile: %s" % failure.getErrorMessage())
623 self.host.memory.asyncDeleteProfile(jid_s) 629 self.host.memory.asyncDeleteProfile(jid_s)
624 raise failure 630 raise failure
625 631
626 # FIXME: we don't catch the case where the JID host is not an XMPP server, and the user 632 # FIXME: we don't catch the case where the JID host is not an XMPP server, and the user
627 # has to wait until the DBUS timeout ; as a consequence, emails are sent to the admins 633 # has to wait until the DBUS timeout ; as a consequence, emails are sent to the admins
628 # and the profile is not deleted. When the host exists, removeProfile is well called. 634 # and the profile is not deleted. When the host exists, removeProfile is well called.
629 d.addCallbacks(lambda dummy: self.sendEmails(None, jid_s, password, jid_s), removeProfile) 635 d.addCallbacks(connected, removeProfile)
630 return d 636 return d