Implement OTP and show received callbacks

This commit is contained in:
2022-10-15 21:51:47 +01:00
parent 8369f44bd4
commit 361b7b96f0
17 changed files with 396 additions and 155 deletions

View File

@@ -1,14 +1,15 @@
import uuid
import orjson
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseBadRequest
from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import render
from django.views import View
from rest_framework.parsers import FormParser
from rest_framework.parsers import FormParser, JSONParser
from rest_framework.views import APIView
from core.forms import HookForm
from core.models import Hook
from core.models import Callback, Hook
def get_hooks(user):
@@ -16,6 +17,28 @@ def get_hooks(user):
return hooks
class HookAPI(APIView):
parser_classes = [JSONParser]
def post(self, request, hook_name):
hook = Hook.objects.get(name=hook_name)
print("DATA FREOM POST", request.data)
callback = Callback.objects.create(
hook=hook,
data=request.data,
)
callback.save()
print("SAVED")
return HttpResponse("OK")
def get(self, request, hook_name):
hook = Hook.objects.get(name=hook_name)
return_data = {"name": hook.name, "hook": hook.hook, "hook_id": hook.id}
return HttpResponse(orjson.dumps(return_data), content_type="application/json")
class Hooks(LoginRequiredMixin, View):
allowed_types = ["modal", "widget", "window", "page"]
window_content = "window-content/hooks.html"
@@ -27,10 +50,10 @@ class Hooks(LoginRequiredMixin, View):
unique = str(uuid.uuid4())[:8]
hooks = get_hooks(request.user)
context = {
"title": f"{type} Demo",
"title": f"Hooks ({type})",
"unique": unique,
"window_content": self.window_content,
"hooks": hooks,
"items": hooks,
}
return render(request, template_name, context)
@@ -98,7 +121,7 @@ class HookAction(LoginRequiredMixin, APIView):
hooks = get_hooks(request.user)
context = {
"hooks": hooks,
"items": hooks,
}
if message:
context["message"] = message
@@ -124,7 +147,7 @@ class HookAction(LoginRequiredMixin, APIView):
hooks = get_hooks(request.user)
context = {
"hooks": hooks,
"items": hooks,
}
if message:
context["message"] = message