-
Notifications
You must be signed in to change notification settings - Fork 0
/
sock.py
35 lines (28 loc) · 1.24 KB
/
sock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf8 -*-
import tornadio2
from models import crud_event_handlers, User
class Connection(tornadio2.SocketConnection):
def on_open(self, request):
user_id = request.get_cookie('oid').value
setattr(self, 'user', User.objects.get(id=user_id))
def on_event(self, name, args=[], kwargs=dict()):
if name in crud_event_handlers:
result = crud_event_handlers[name](self, *args, **kwargs)
if isinstance(result, tuple):
return result
else:
return None, result
else:
return super(Connection, self).on_event(name, args, kwargs)
# FIXME: it's fake
@tornadio2.event('join-board')
def on_join_board(self, *args, **kwargs):
self.emit('joined-board',
*[{"ok": 0, "visitors":
[{"username": "admin", "email": "[email protected]",
"_id": self.user._id, "__v": 0,
"isFirstLogin": False, "roles": [],
"joined": "2014-06-14T11:46:48.575Z", "fullname": "",
"role": {"name": "admin",
"desc": "Admin - full control"}}],
"message": "isMember"}])