def post(self, request, *args, **kwargs): if 'pubkey_fingerprint' in request.DATA: try: user = PGPUser.objects.get(pubkey_fingerprint=request.DATA['pubkey_fingerprint']) except PGPUser.DoesNotExist: return Response({'error': 'Unregistered public key'}, status=403) challengeStr = randomString() cache.set(user.pubkey_fingerprint, challengeStr, 60) challenge = str(GPG.encrypt(challengeStr, user.pubkey_fingerprint, always_trust=True)) return Response({'challenge': challenge}, status=200) return Response({'error': 'pubkey_fingerprint must be provided'}, status=400)
def post(self, request, *args, **kwargs): form = RegisterForm(request.POST, request.FILES) if form.is_valid(): pubkey = form.pubkey result = GPG.import_keys(pubkey) if result.imported == 1: pubkey_info = get_key_info(result.fingerprints[0]) PGPUser.objects.create_user(form.cleaned_data['username'], pubkey, pubkey_info) return redirect('home') else: return render(request, self.template_name, {'form': form, 'import_error': True}) return render(request, self.template_name, {'form': form})