Mercurial > libervia-backend
comparison src/memory/memory.py @ 1693:35426d58471c
core (memory): stopSession implementation
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 Nov 2015 16:48:41 +0100 |
parents | a40124e03baf |
children | 3c608d660f0b |
comparison
equal
deleted
inserted
replaced
1692:0fdd8fe34fbf | 1693:35426d58471c |
---|---|
355 auth_d.addCallback(doStartSession) | 355 auth_d.addCallback(doStartSession) |
356 return auth_d | 356 return auth_d |
357 | 357 |
358 return self.host.initialised.addCallback(backendInitialised) | 358 return self.host.initialised.addCallback(backendInitialised) |
359 | 359 |
360 def stopSession(self, profile): | |
361 """Delete a profile session | |
362 | |
363 @param profile: %(doc_profile)s | |
364 """ | |
365 if self.host.isConnected(profile): | |
366 log.debug(u"Disconnecting profile because of session stop") | |
367 self.host.disconnect(profile) | |
368 self.auth_sessions.profileDelUnique(profile) | |
369 try: | |
370 self._entities_cache[profile] | |
371 except KeyError: | |
372 log.warning(u"Profile was not in cache") | |
373 | |
360 def _isSessionStarted(self, profile_key): | 374 def _isSessionStarted(self, profile_key): |
361 return self.isSessionStarted(self.getProfileName(profile_key)) | 375 return self.isSessionStarted(self.getProfileName(profile_key)) |
362 | 376 |
363 def isSessionStarted(self, profile): | 377 def isSessionStarted(self, profile): |
364 try: | 378 try: |
372 """Authenticate the profile. | 386 """Authenticate the profile. |
373 | 387 |
374 @param password (unicode): the SàT profile password | 388 @param password (unicode): the SàT profile password |
375 @param profile: %(doc_profile)s | 389 @param profile: %(doc_profile)s |
376 @return (D): a deferred None in case of success, a failure otherwise. | 390 @return (D): a deferred None in case of success, a failure otherwise. |
391 @raise exceptions.PasswordError: the password does not match | |
377 """ | 392 """ |
378 session_data = self.auth_sessions.profileGetUnique(profile) | 393 session_data = self.auth_sessions.profileGetUnique(profile) |
379 if not password and session_data: | 394 if not password and session_data: |
380 # XXX: this allows any frontend to connect with the empty password as soon as | 395 # XXX: this allows any frontend to connect with the empty password as soon as |
381 # the profile has been authenticated at least once before. It is OK as long as | 396 # the profile has been authenticated at least once before. It is OK as long as |
383 return defer.succeed(None) | 398 return defer.succeed(None) |
384 | 399 |
385 def check_result(result): | 400 def check_result(result): |
386 if not result: | 401 if not result: |
387 log.warning(u'Authentication failure of profile {}'.format(profile)) | 402 log.warning(u'Authentication failure of profile {}'.format(profile)) |
388 raise exceptions.PasswordError(u"The provided profile password doesn't match.") | 403 raise failure.Failure(exceptions.PasswordError(u"The provided profile password doesn't match.")) |
389 if not session_data: # avoid to create two profile sessions when password if specified | 404 if not session_data: # avoid to create two profile sessions when password if specified |
390 return self.newAuthSession(password, profile) | 405 return self.newAuthSession(password, profile) |
391 | 406 |
392 d = self.asyncGetParamA(C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], profile_key=profile) | 407 d = self.asyncGetParamA(C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], profile_key=profile) |
393 d.addCallback(lambda sat_cipher: PasswordHasher.verify(password, sat_cipher)) | 408 d.addCallback(lambda sat_cipher: PasswordHasher.verify(password, sat_cipher)) |