-
Notifications
You must be signed in to change notification settings - Fork 4
/
views.py
24 lines (22 loc) · 817 Bytes
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import binascii
import json
from django.http import HttpResponse, HttpResponseNotAllowed, HttpResponseBadRequest
from django.views.decorators.csrf import csrf_exempt
from .polo import get_hash
@csrf_exempt
def reply(request):
if request.method == 'POST':
params = request.POST
elif request.method == 'GET':
params = request.GET
else:
return HttpResponseNotAllowed(['POST', 'GET'])
txn_id = params.get('txn')
challenge = params.get('challenge')
if not challenge:
return HttpResponseBadRequest('Missing parameters.')
challenge_bytes = bytes(challenge, 'utf8')
digest = get_hash(challenge_bytes)
digest_hex = str(binascii.hexlify(digest), 'ascii')
response_data = {'txn':txn_id, 'digest':digest_hex}
return HttpResponse(json.dumps(response_data), content_type='application/json')