From 34be41d165d58acdc408fb37606b3b9f628ecd2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evren=20Esat=20=C3=96zkan?= Date: Thu, 28 Jul 2016 13:55:58 +0300 Subject: [PATCH] trying to fix multiple replies caused from simultaneous logins rref #5367 rref #5366 ref zetaops/zengine#66 ref zetaops/zengine#65 --- zengine/messaging/lib.py | 6 ++++++ zengine/views/auth.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/zengine/messaging/lib.py b/zengine/messaging/lib.py index 7214ae9a..fc0d3469 100644 --- a/zengine/messaging/lib.py +++ b/zengine/messaging/lib.py @@ -135,6 +135,12 @@ def bind_private_channel(self, sess_id): self.prv_exchange)) mq_channel.queue_bind(exchange=self.prv_exchange, queue=sess_id) + def unbind_private_channel(self, sess_id): + mq_channel = self._connect_mq() + log.debug("Unbinding existing queue from private exchange: Q:%s --> E:%s" % (sess_id, + self.prv_exchange)) + mq_channel.queue_unbind(queue=sess_id, exchange=self.prv_exchange) + def send_notification(self, title, message, typ=1, url=None): """ sends message to users private mq exchange diff --git a/zengine/views/auth.py b/zengine/views/auth.py index 8f2bb95e..c9aed142 100644 --- a/zengine/views/auth.py +++ b/zengine/views/auth.py @@ -9,7 +9,8 @@ from pyoko import fields from zengine.forms.json_form import JsonForm -from zengine.lib.cache import UserSessionID, KeepAlive +from zengine.lib.cache import UserSessionID, KeepAlive, Session +from zengine.log import log from zengine.messaging import Notify from zengine.views.base import SimpleView @@ -59,10 +60,19 @@ def _do_upgrade(self): self.current.output['cmd'] = 'upgrade' self.current.output['user_id'] = self.current.user_id self.current.user.is_online(True) + self.terminate_existing_login() self.current.user.bind_private_channel(self.current.session.sess_id) user_sess = UserSessionID(self.current.user_id) user_sess.set(self.current.session.sess_id) + def terminate_existing_login(self): + existing_sess_id = UserSessionID(self.current.user_id).get() + if self.current.session.sess_id == existing_sess_id: + log.info("TERMINATE: this should not happen!") + if existing_sess_id: + self.current.user.unbind_private_channel(existing_sess_id) + Session(existing_sess_id).delete() + def do_view(self): """ Authenticate user with given credentials.