funkwhale/api/funkwhale_api/common/consumers.py
Eliot Berriot b9f0c6aecd
Revert "Merge branch '629-cookie-auth' into 'develop'"
This reverts commit 8b47af8b81, reversing
changes made to c0055b3b20.
2019-03-15 15:52:30 +01:00

20 lines
622 B
Python

from channels.generic.websocket import JsonWebsocketConsumer
from funkwhale_api.common import channels
class JsonAuthConsumer(JsonWebsocketConsumer):
def connect(self):
try:
assert self.scope["user"].pk is not None
except (AssertionError, AttributeError, KeyError):
return self.close()
return self.accept()
def accept(self):
super().accept()
for group in self.groups:
channels.group_add(group, self.channel_name)
for group in self.scope["user"].get_channels_groups():
channels.group_add(group, self.channel_name)