mirror of
https://github.com/task-17-lct/backend.git
synced 2024-12-18 07:26:16 +03:00
25 lines
722 B
Python
25 lines
722 B
Python
|
import functools
|
||
|
|
||
|
from channels.generic.websocket import AsyncJsonWebsocketConsumer, JsonWebsocketConsumer
|
||
|
|
||
|
|
||
|
def login_required(func):
|
||
|
@functools.wraps(func)
|
||
|
def wrapper(self, *args, **kwargs):
|
||
|
if not self.scope.get("user", False) or not self.scope["user"].is_authenticated:
|
||
|
self.send_error("Login is required")
|
||
|
else:
|
||
|
return func(self, *args, **kwargs)
|
||
|
|
||
|
return wrapper
|
||
|
|
||
|
|
||
|
class BaseConsumer(AsyncJsonWebsocketConsumer):
|
||
|
async def send_error(self, msg):
|
||
|
await self.send_json({"type": "error", "data": {"msg": msg}})
|
||
|
|
||
|
|
||
|
class SyncBaseConsumer(JsonWebsocketConsumer):
|
||
|
def send_error(self, msg):
|
||
|
self.send_json({"type": "error", "data": {"msg": msg}})
|