def get(self, request): new_key = CaptchaStore.pick() to_json_response = { "key": new_key, "image_url": captcha_image_url(new_key), "audio_url": captcha_audio_url(new_key) if ca_settings.CAPTCHA_FLITE_PATH else None, } return SuccessResponse(to_json_response)
def captcha_refresh(request): """ Return json with new captcha for ajax refresh request """ if not request.is_ajax(): raise Http404 new_key = CaptchaStore.pick() to_json_response = { 'key': new_key, 'image_url': captcha_image_url(new_key), 'audio_url': captcha_audio_url(new_key) if settings.CAPTCHA_FLITE_PATH else None } return HttpResponse(json.dumps(to_json_response), content_type='application/json')
def captcha_refresh(request): """ Return json with new captcha for ajax refresh request """ if not request.is_ajax(): raise Http404 new_key = CaptchaStore.pick() to_json_response = { 'key': new_key, 'image_url': captcha_image_url(new_key), 'audio_url': captcha_audio_url(new_key) if settings.CAPTCHA_FLITE_PATH else None } return HttpResponse(json.dumps(to_json_response), content_type='application/json')
def captcha_refresh(request): """ Return json with new captcha for ajax refresh request """ if not request.is_ajax(): raise Http404 new_key = CaptchaStore.pick() to_json_response = { "key": new_key, "image_url": captcha_image_url(new_key), "audio_url": captcha_audio_url(new_key) if settings.CAPTCHA_ESPEAK_PATH else None, } return HttpResponse(json.dumps(to_json_response), content_type="application/json")
def dispatch(self, request, *args, **kwargs): if request.method == 'GET': # generate captcha captcha_key = captcha_models.CaptchaStore.pick() captcha_img_url = captcha_helpers.captcha_image_url(captcha_key) if settings.CAPTCHA_FLITE_PATH: captcha_audio_url = \ captcha_helpers.captcha_audio_url(captcha_key) else: captcha_audio_url = None context = {'captcha_key': captcha_key, 'captcha_img_url': captcha_img_url, 'captcha_audio_url': captcha_audio_url} return render(request, self.template_name, context) return super().dispatch(request, *args, **kwargs)
def captcha_refresh(request): """ Return json with new captcha for ajax refresh request """ if not request.headers.get('x-requested-with') == 'XMLHttpRequest': raise Http404 new_key = CaptchaStore.pick() to_json_response = { "key": new_key, "image_url": captcha_image_url(new_key), "audio_url": captcha_audio_url(new_key) if settings.CAPTCHA_FLITE_PATH else None, } return HttpResponse(json.dumps(to_json_response), content_type="application/json")