mirror of
https://github.com/magnum-opus-nn-cp/backend.git
synced 2024-11-10 18:06:33 +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}})
|