Skip to content

Commit

Permalink
trying to fix multiple replies caused from simultaneous logins
Browse files Browse the repository at this point in the history
rref #5367
rref #5366

ref #66
ref #65
  • Loading branch information
evrenesat committed Jul 28, 2016
1 parent c4ac300 commit 34be41d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions zengine/messaging/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion zengine/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 34be41d

Please sign in to comment.