summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/application.py14
-rw-r--r--service/pixelated/resources/login_resource.py8
-rw-r--r--service/test/unit/resources/test_login_resource.py1
-rw-r--r--service/test/unit/test_application.py14
4 files changed, 26 insertions, 11 deletions
diff --git a/service/pixelated/application.py b/service/pixelated/application.py
index 8eba0cd9..af29bc5f 100644
--- a/service/pixelated/application.py
+++ b/service/pixelated/application.py
@@ -44,6 +44,10 @@ class ServicesFactory(object):
def __init__(self, mode):
self._services_by_user = {}
self.mode = mode
+ self._map_email = {}
+
+ def map_email(self, username, user_id):
+ self._map_email[username] = user_id
def is_logged_in(self, user_id):
return user_id in self._services_by_user
@@ -51,7 +55,10 @@ class ServicesFactory(object):
def services(self, user_id):
return self._services_by_user[user_id]
- def log_out_user(self, user_id):
+ def log_out_user(self, user_id, using_email=False):
+ if using_email:
+ user_id = self._map_email[user_id.split('@')[0]]
+
if self.is_logged_in(user_id):
_services = self._services_by_user[user_id]
_services.close()
@@ -78,7 +85,7 @@ class SingleUserServicesFactory(object):
def services(self, user_id):
return self._services
- def log_out_user(self, user_id):
+ def log_out_user(self, user_id, using_email=False):
reactor.stop()
@@ -149,7 +156,8 @@ def add_top_level_system_callbacks(deferred, services_factory):
def _log_user_out(event, user_data):
log.info('Invalid soledad token, logging out %s' % user_data)
- services_factory.log_out_user(user_data['uuid'])
+ user_data = {'user_id': user_data['uuid']} if 'uuid' in user_data else {'user_id': user_data, 'using_email': True}
+ services_factory.log_out_user(**user_data)
def _log_user_out_on_token_expire(leap_session):
register(events.SOLEDAD_INVALID_AUTH_TOKEN, _log_user_out)
diff --git a/service/pixelated/resources/login_resource.py b/service/pixelated/resources/login_resource.py
index 55db6970..eaa21bd9 100644
--- a/service/pixelated/resources/login_resource.py
+++ b/service/pixelated/resources/login_resource.py
@@ -161,15 +161,13 @@ class LoginResource(BaseResource):
user_id = leap_session.user_auth.uuid
if not self._services_factory.is_logged_in(user_id):
yield self._services_factory.create_services_from(leap_session)
- self._init_http_session(request, user_id)
-
- @defer.inlineCallbacks
- def _initialize_services(self, leap_session):
- yield self._services_factory.create_services_from(leap_session)
+ self._services_factory.map_email(self.creds.username, user_id)
if leap_session.fresh_account:
yield add_welcome_mail(leap_session.mail_store)
+ self._init_http_session(request, user_id)
+
def _init_http_session(self, request, user_id):
session = IPixelatedSession(request.getSession())
session.user_uuid = user_id
diff --git a/service/test/unit/resources/test_login_resource.py b/service/test/unit/resources/test_login_resource.py
index 4076946a..09bc79bf 100644
--- a/service/test/unit/resources/test_login_resource.py
+++ b/service/test/unit/resources/test_login_resource.py
@@ -180,6 +180,7 @@ class TestLoginPOST(unittest.TestCase):
def assert_login_setup_service_for_user(_):
verify(self.portal).login(ANY(), None, IResource)
verify(self.services_factory).create_services_from(self.leap_session)
+ verify(self.services_factory).map_email('ayoyo', 'some_user_uuid')
interstitial_js_in_template = '<script src="startup-assets/Interstitial.js"></script>'
self.assertIn(interstitial_js_in_template, self.request.written[0])
self.assertTrue(self.resource.is_logged_in(self.request))
diff --git a/service/test/unit/test_application.py b/service/test/unit/test_application.py
index 43b0cee1..82a956b8 100644
--- a/service/test/unit/test_application.py
+++ b/service/test/unit/test_application.py
@@ -94,14 +94,22 @@ class ApplicationTest(unittest.TestCase):
pixelated.application.add_top_level_system_callbacks(d, services_factory_mock)
- def _assert_user_logged_out(_):
+ def _assert_user_logged_out_using_uuid(_):
used_arguments = register_mock.call_args[0]
self.assertIsNotNone(used_arguments)
soledad_invalid_auth_event = used_arguments[0]
self.assertEqual(soledad_invalid_auth_event, events.SOLEDAD_INVALID_AUTH_TOKEN)
used_log_out_method = used_arguments[1]
used_log_out_method(events.SOLEDAD_INVALID_AUTH_TOKEN, {'uuid': 'some_uuid'})
- mock_service_log_user_out.assert_called_once_with('some_uuid')
+ mock_service_log_user_out.assert_called_once_with(user_id='some_uuid')
- d.addCallback(_assert_user_logged_out)
+ def _assert_user_logged_out_using_email_id(_):
+ mock_service_log_user_out.reset_mock()
+ used_arguments = register_mock.call_args[0]
+ used_log_out_method = used_arguments[1]
+ used_log_out_method(events.SOLEDAD_INVALID_AUTH_TOKEN, 'haha@ayo.yo')
+ mock_service_log_user_out.assert_called_once_with(user_id='haha@ayo.yo', using_email=True)
+
+ d.addCallback(_assert_user_logged_out_using_uuid)
+ d.addCallback(_assert_user_logged_out_using_email_id)
return d