mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-04-10 20:41:47 +00:00
Compare commits
8 Commits
63eb3bebef
...
2171d7fda9
| Author | SHA1 | Date | |
|---|---|---|---|
|
2171d7fda9
|
|||
|
3c4ccfb103
|
|||
|
04c7e4b518
|
|||
|
beb0ba915d
|
|||
|
ac15ab3729
|
|||
|
15230cb361
|
|||
|
b5b8dc104c
|
|||
|
55aa41acfd
|
@@ -5,6 +5,7 @@ import premailer
|
|||||||
import simplejson
|
import simplejson
|
||||||
import urllib
|
import urllib
|
||||||
import hmac
|
import hmac
|
||||||
|
import hashlib
|
||||||
|
|
||||||
from envparse import env
|
from envparse import env
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@@ -408,13 +409,15 @@ class RecieveForumWebhook(generic.View):
|
|||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
computed = f"sha256={hmac.new(env('FORUM_WEBHOOK_SECRET').encode(), request.body, digestmod='sha256').hexdigest()}"
|
computed = f"sha256={hmac.new(env('FORUM_WEBHOOK_SECRET').encode(), request.body, hashlib.sha256).hexdigest()}"
|
||||||
if request.POST.get('X-Discourse-Event-Signature') == computed: # and request.POST.get('X-Discourse-Event') == "topic_created":
|
print(computed)
|
||||||
body = json.loads(request.body.decode('utf-8'))
|
if not hmac.compare_digest(request.headers.get('X-Discourse-Event-Signature'), computed):
|
||||||
event_id = int(body['title'][1:5]) # find the ID, force convert it to an int to eliminate leading zeros
|
return HttpResponseForbidden('Invalid signature header')
|
||||||
event = models.Event.objects.filter(pk=event_id).first()
|
body = simplejson.loads(request.body.decode('utf-8'))
|
||||||
if event:
|
event_id = int(body['topic']['title'][1:6]) # find the ID, force convert it to an int to eliminate leading zeros
|
||||||
event.forum_url = "https://forum.nottinghamtec.co.uk/t/{}"
|
event = models.Event.objects.filter(pk=event_id).first()
|
||||||
event.save()
|
if event:
|
||||||
return HttpResponse(status=200)
|
event.forum_url = f"https://forum.nottinghamtec.co.uk/t/{body['topic']['slug']}"
|
||||||
|
event.save()
|
||||||
|
return HttpResponse(status=202)
|
||||||
return HttpResponse(status=204)
|
return HttpResponse(status=204)
|
||||||
|
|||||||
Reference in New Issue
Block a user