memory: Sessions.newSession can be called with a forced session ID
This commit is contained in:
parent
a67c8094f5
commit
830b6d8ef6
4 changed files with 9 additions and 7 deletions
|
|
@ -47,14 +47,16 @@ class Sessions(object):
|
|||
self._sessions = dict()
|
||||
self.timeout = timeout or Sessions.DEFAULT_TIMEOUT
|
||||
|
||||
def newSession(self, session_data=None, profile=None):
|
||||
def newSession(self, session_data=None, session_id=None, profile=None):
|
||||
""" Create a new session
|
||||
@param session_data: mutable data to use, default to a dict
|
||||
@param session_id (str): force the session_id to the given string
|
||||
@param profile: if set, the session is owned by the profile,
|
||||
and profileGet must be used instead of __getitem__
|
||||
@return: session_id, session_data
|
||||
"""
|
||||
session_id = str(uuid4())
|
||||
if session_id is None:
|
||||
session_id = str(uuid4())
|
||||
timer = reactor.callLater(self.timeout, self._purgeSession, session_id)
|
||||
if session_data is None:
|
||||
session_data = {}
|
||||
|
|
@ -268,7 +270,7 @@ class Memory(object):
|
|||
"""
|
||||
def gotPersonalKey(personal_key):
|
||||
"""Create the session for this profile and store the personal key"""
|
||||
self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile)
|
||||
self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=profile)
|
||||
log.debug('auth session created for profile %s' % profile)
|
||||
|
||||
d = PersistentDict(C.MEMORY_CRYPTO_NAMESPACE, profile).load()
|
||||
|
|
@ -319,7 +321,7 @@ class Memory(object):
|
|||
@return: Deferred
|
||||
"""
|
||||
personal_key = BlockCipher.getRandomKey(base64=True) # generated once for all and saved in a PersistentDict
|
||||
self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, name) # will be encrypted by setParam
|
||||
self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=name) # will be encrypted by setParam
|
||||
d = self.params.asyncCreateProfile(name)
|
||||
d.addCallback(lambda dummy: self.setParam(C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=name))
|
||||
return d
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ SàT team""" % {'login': login, 'jid': "%s@%s" % (login, self.getConfig('new_acc
|
|||
@param password (str): the new password
|
||||
@param profile (str): %(doc_profile)s
|
||||
"""
|
||||
session_id, dummy = self._sessions.newSession({'new_password': password}, profile)
|
||||
session_id, dummy = self._sessions.newSession({'new_password': password}, profile=profile)
|
||||
form_ui = xml_tools.XMLUI("form", title=D_("Change your password?"), submit_id=self.__change_password_id, session_id=session_id)
|
||||
form_ui.addText(D_("Note for advanced users: this will actually change both your SàT profile password AND your XMPP account password."))
|
||||
form_ui.addText(D_("Continue with changing the password?"))
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class RegisterAccount(object):
|
|||
|
||||
session_data['user'], host, resource = jid.parse(session_data['JabberID'])
|
||||
session_data['server'] = session_data[C.FORCE_SERVER_PARAM] or host
|
||||
session_id, dummy = self._sessions.newSession(session_data, profile)
|
||||
session_id, dummy = self._sessions.newSession(session_data, profile=profile)
|
||||
form_ui = xml_tools.XMLUI("form", title=D_("Register new account"), submit_id=self.__register_account_id, session_id=session_id)
|
||||
form_ui.addText(D_("Do you want to register a new XMPP account [%(user)s] on server %(server)s ?") % {'user': session_data['user'], 'server': session_data['server']})
|
||||
return {'xmlui': form_ui.toXml()}
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class ProfileManager(object):
|
|||
server = self.host.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile)
|
||||
if not server:
|
||||
server = jid.parse(self.host.memory.getParamA('JabberID', "Connection", profile_key=profile))[1]
|
||||
session_id, session_data = self._sessions.newSession({'count': 0, 'server': server}, profile)
|
||||
session_id, session_data = self._sessions.newSession({'count': 0, 'server': server}, profile=profile)
|
||||
if session_data['count'] > 2: # 3 attempts with a new password after the initial try
|
||||
self._sessions.profileDelUnique(profile)
|
||||
_dialog = xml_tools.XMLUI('popup', title=D_('Connection error'))
|
||||
|
|
|
|||
Loading…
Reference in a new issue