comparison sat/plugins/plugin_misc_account.py @ 2765:378188abe941

misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
author Goffi <goffi@goffi.org>
date Fri, 11 Jan 2019 11:13:15 +0100
parents 56f94936df1e
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2764:92af49cde255 2765:378188abe941
223 - None or "": register a new JID on the local XMPP server 223 - None or "": register a new JID on the local XMPP server
224 @param profile 224 @param profile
225 @return Deferred 225 @return Deferred
226 """ 226 """
227 d = self.createProfile(password, jid_s, profile) 227 d = self.createProfile(password, jid_s, profile)
228 d.addCallback(lambda dummy: self.sendEmails(email, profile)) 228 d.addCallback(lambda __: self.sendEmails(email, profile))
229 return d 229 return d
230 230
231 def createProfile(self, password, jid_s, profile): 231 def createProfile(self, password, jid_s, profile):
232 """Register a new profile and its associated XMPP account. 232 """Register a new profile and its associated XMPP account.
233 233
244 244
245 if profile.lower() in self.getConfig("reserved_list"): 245 if profile.lower() in self.getConfig("reserved_list"):
246 return defer.fail(Failure(exceptions.ConflictError)) 246 return defer.fail(Failure(exceptions.ConflictError))
247 247
248 d = self.host.memory.createProfile(profile, password) 248 d = self.host.memory.createProfile(profile, password)
249 d.addCallback(lambda dummy: self.profileCreated(password, jid_s, profile)) 249 d.addCallback(lambda __: self.profileCreated(password, jid_s, profile))
250 return d 250 return d
251 251
252 def profileCreated(self, password, jid_s, profile): 252 def profileCreated(self, password, jid_s, profile):
253 """Create the XMPP account and set the profile connection parameters. 253 """Create the XMPP account and set the profile connection parameters.
254 254
265 else: 265 else:
266 jid_s = profile + u"@" + self.getNewAccountDomain() 266 jid_s = profile + u"@" + self.getNewAccountDomain()
267 jid_ = jid.JID(jid_s) 267 jid_ = jid.JID(jid_s)
268 d = self.host.plugins["XEP-0077"].registerNewAccount(jid_, password) 268 d = self.host.plugins["XEP-0077"].registerNewAccount(jid_, password)
269 269
270 def setParams(dummy): 270 def setParams(__):
271 self.host.memory.setParam( 271 self.host.memory.setParam(
272 "JabberID", jid_s, "Connection", profile_key=profile 272 "JabberID", jid_s, "Connection", profile_key=profile
273 ) 273 )
274 d = self.host.memory.setParam( 274 d = self.host.memory.setParam(
275 "Password", password, "Connection", profile_key=profile 275 "Password", password, "Connection", profile_key=profile
278 278
279 def removeProfile(failure): 279 def removeProfile(failure):
280 self.host.memory.asyncDeleteProfile(profile) 280 self.host.memory.asyncDeleteProfile(profile)
281 return failure 281 return failure
282 282
283 d.addCallback(lambda dummy: self.host.memory.startSession(password, profile)) 283 d.addCallback(lambda __: self.host.memory.startSession(password, profile))
284 d.addCallback(setParams) 284 d.addCallback(setParams)
285 d.addCallback(lambda dummy: self.host.memory.stopSession(profile)) 285 d.addCallback(lambda __: self.host.memory.stopSession(profile))
286 d.addErrback(removeProfile) 286 d.addErrback(removeProfile)
287 return d 287 return d
288 288
289 def _sendEmailEb(self, failure_, email): 289 def _sendEmailEb(self, failure_, email):
290 # TODO: return error code to user 290 # TODO: return error code to user
315 ) 315 )
316 d_admin = sat_email.sendEmail(self.host, admins_emails, subject, body) 316 d_admin = sat_email.sendEmail(self.host, admins_emails, subject, body)
317 317
318 admins_emails_txt = u", ".join([u"<" + addr + u">" for addr in admins_emails]) 318 admins_emails_txt = u", ".join([u"<" + addr + u">" for addr in admins_emails])
319 d_admin.addCallbacks( 319 d_admin.addCallbacks(
320 lambda dummy: log.debug( 320 lambda __: log.debug(
321 u"Account creation notification sent to admin(s) {}".format( 321 u"Account creation notification sent to admin(s) {}".format(
322 admins_emails_txt 322 admins_emails_txt
323 ) 323 )
324 ), 324 ),
325 lambda dummy: log.error( 325 lambda __: log.error(
326 u"Failed to send account creation notification to admin {}".format( 326 u"Failed to send account creation notification to admin {}".format(
327 admins_emails_txt 327 admins_emails_txt
328 ) 328 )
329 ), 329 ),
330 ) 330 )
341 # XXX: this will not fail when the email address doesn't exist 341 # XXX: this will not fail when the email address doesn't exist
342 # FIXME: check email reception to validate email given by the user 342 # FIXME: check email reception to validate email given by the user
343 # FIXME: delete the profile if the email could not been sent? 343 # FIXME: delete the profile if the email could not been sent?
344 d_user = sat_email.sendEmail(self.host, [email], subject, body) 344 d_user = sat_email.sendEmail(self.host, [email], subject, body)
345 d_user.addCallbacks( 345 d_user.addCallbacks(
346 lambda dummy: log.debug( 346 lambda __: log.debug(
347 u"Account creation confirmation sent to <{}>".format(email) 347 u"Account creation confirmation sent to <{}>".format(email)
348 ), 348 ),
349 self._sendEmailEb, 349 self._sendEmailEb,
350 ) 350 )
351 return defer.DeferredList([d_user, d_admin]) 351 return defer.DeferredList([d_user, d_admin])
483 """Ask for a confirmation before changing the XMPP account and SàT profile passwords. 483 """Ask for a confirmation before changing the XMPP account and SàT profile passwords.
484 484
485 @param password (str): the new password 485 @param password (str): the new password
486 @param profile (str): %(doc_profile)s 486 @param profile (str): %(doc_profile)s
487 """ 487 """
488 session_id, dummy = self._sessions.newSession( 488 session_id, __ = self._sessions.newSession(
489 {"new_password": password}, profile=profile 489 {"new_password": password}, profile=profile
490 ) 490 )
491 form_ui = xml_tools.XMLUI( 491 form_ui = xml_tools.XMLUI(
492 "form", 492 "form",
493 title=D_("Change your password?"), 493 title=D_("Change your password?"),
509 """ 509 """
510 client = self.host.getClient(profile) 510 client = self.host.getClient(profile)
511 password = self._sessions.profileGet(data["session_id"], profile)["new_password"] 511 password = self._sessions.profileGet(data["session_id"], profile)["new_password"]
512 del self._sessions[data["session_id"]] 512 del self._sessions[data["session_id"]]
513 513
514 def passwordChanged(dummy): 514 def passwordChanged(__):
515 d = self.host.memory.setParam( 515 d = self.host.memory.setParam(
516 C.PROFILE_PASS_PATH[1], 516 C.PROFILE_PASS_PATH[1],
517 password, 517 password,
518 C.PROFILE_PASS_PATH[0], 518 C.PROFILE_PASS_PATH[0],
519 profile_key=profile, 519 profile_key=profile,
520 ) 520 )
521 d.addCallback( 521 d.addCallback(
522 lambda dummy: self.host.memory.setParam( 522 lambda __: self.host.memory.setParam(
523 "Password", password, "Connection", profile_key=profile 523 "Password", password, "Connection", profile_key=profile
524 ) 524 )
525 ) 525 )
526 confirm_ui = xml_tools.XMLUI("popup", title=D_("Confirmation")) 526 confirm_ui = xml_tools.XMLUI("popup", title=D_("Confirmation"))
527 confirm_ui.addText(D_("Your password has been changed.")) 527 confirm_ui.addText(D_("Your password has been changed."))
574 @param data 574 @param data
575 @param profile 575 @param profile
576 """ 576 """
577 client = self.host.getClient(profile) 577 client = self.host.getClient(profile)
578 578
579 def userDeleted(dummy): 579 def userDeleted(__):
580 580
581 # FIXME: client should be disconnected at this point, so 2 next loop should be removed (to be confirmed) 581 # FIXME: client should be disconnected at this point, so 2 next loop should be removed (to be confirmed)
582 for jid_ in client.roster._jids: # empty roster 582 for jid_ in client.roster._jids: # empty roster
583 client.presence.unsubscribe(jid_) 583 client.presence.unsubscribe(jid_)
584 584
592 ) 592 )
593 if "GROUPBLOG" in self.host.plugins: 593 if "GROUPBLOG" in self.host.plugins:
594 d = self.host.plugins["GROUPBLOG"].deleteAllGroupBlogsAndComments( 594 d = self.host.plugins["GROUPBLOG"].deleteAllGroupBlogsAndComments(
595 profile_key=profile 595 profile_key=profile
596 ) 596 )
597 d.addCallback(lambda dummy: delete_profile()) 597 d.addCallback(lambda __: delete_profile())
598 else: 598 else:
599 delete_profile() 599 delete_profile()
600 600
601 return defer.succeed({}) 601 return defer.succeed({})
602 602
737 else: 737 else:
738 raise exceptions.ConflictError 738 raise exceptions.ConflictError
739 739
740 d = self.createProfile(password, jid_s, jid_s) 740 d = self.createProfile(password, jid_s, jid_s)
741 d.addCallback( 741 d.addCallback(
742 lambda dummy: self.host.memory.getProfileName(jid_s) 742 lambda __: self.host.memory.getProfileName(jid_s)
743 ) # checks if the profile has been successfuly created 743 ) # checks if the profile has been successfuly created
744 d.addCallback(self.host.connect, password, {}, 0) 744 d.addCallback(self.host.connect, password, {}, 0)
745 745
746 def connected(result): 746 def connected(result):
747 self.sendEmails(None, profile=jid_s) 747 self.sendEmails(None, profile=jid_s)