plugin account: fixed profile creation: session is started to set the connection parameters, then stopped

This commit is contained in:
Goffi 2015-11-27 16:54:11 +01:00
commit 44360c5b9b

View file

@ -159,7 +159,7 @@ class MiscAccount(object):
def generatePassword(self):
"""Generate a password with random characters.
@return unicode
"""
random.seed()
@ -175,11 +175,12 @@ class MiscAccount(object):
@param email (unicode): where to send to confirmation email to
@param password (unicode): password chosen by the user
while be used for profile *and* XMPP account
@param jid_s (unicode): JID to re-use or to register:
- non empty value: bind this JID to the new sat profile
- None or "": register a new JID on the local XMPP server
@param profile
@return Deferred
@return Deferred
"""
if not password or not profile:
raise exceptions.DataError
@ -214,13 +215,15 @@ class MiscAccount(object):
def setParams(dummy):
self.host.memory.setParam("JabberID", jid_s, "Connection", profile_key=profile)
d = self.host.memory.setParam("Password", password, "Connection", profile_key=profile)
return d.addCallback(lambda dummy: self.host.memory.auth_sessions.profileDelUnique(profile))
return d
def removeProfile(failure):
self.host.memory.asyncDeleteProfile(profile)
return failure
d.addCallback(lambda dummy: self.host.memory.startSession(password, profile))
d.addCallback(setParams)
d.addCallback(lambda dummy: self.host.memory.stopSession(profile))
d.addErrback(removeProfile)
return d
@ -515,12 +518,12 @@ http://www.salut-a-toi.org
def asyncConnectWithXMPPCredentials(self, jid_s, password):
"""Create and connect a new SàT profile using the given XMPP credentials.
Re-use given JID and XMPP password for the profile name and profile password.
@param jid_s (unicode): JID
@param password (unicode): XMPP password
@return Deferred(bool)
@raise exceptions.PasswordError, exceptions.ConflictError
@raise exceptions.PasswordError, exceptions.ConflictError
"""
try: # be sure that the profile doesn't exist yet
self.host.memory.getProfileName(jid_s)
@ -536,7 +539,7 @@ http://www.salut-a-toi.org
def removeProfile(failure): # profile has been successfully created but the XMPP credentials are wrong!
log.debug("Removing previously auto-created profile: %s" % failure.getErrorMessage())
self.host.memory.asyncDeleteProfile(jid_s)
raise failure
raise failure
d.addErrback(removeProfile)
return d