当前位置: 首页>>代码示例>>Python>>正文


Python models.CaptchaStore类代码示例

本文整理汇总了Python中captcha.models.CaptchaStore的典型用法代码示例。如果您正苦于以下问题:Python CaptchaStore类的具体用法?Python CaptchaStore怎么用?Python CaptchaStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CaptchaStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clean

    def clean(self, value):
        super(CaptchaField, self).clean(value)
        CaptchaStore.remove_expired()

        response, value[1] = (value[1] or '').strip().lower(), ''
        hashkey = value[0]

        if settings.CAPTCHA_TEST_MODE and response.lower() == 'passed':
            # automatically pass the test
            try:
                # try to delete the captcha based on its hash
                CaptchaStore.objects.get(hashkey=hashkey).delete()
            except CaptchaStore.DoesNotExist:
                # ignore errors
                pass
        elif not self.required and not response:
            pass
        else:
            # let enable validity_count times
            # of clean() method
            if hashkey in self.validity_cache and self.validity_cache[hashkey] > 0:
                self.validity_cache[hashkey] -= 1
                return value
            try:
                captcha = CaptchaStore.objects.get(
                    response=response,
                    hashkey=hashkey,
                    expiration__gt=get_safe_now())
                self.validity_cache[hashkey] = self.validity_count - 1
                captcha.delete()
            except CaptchaStore.DoesNotExist:
                raise ValidationError(
                    getattr(self, 'error_messages', {}).get('invalid',
                                                            _('Invalid CAPTCHA')))
        return value
开发者ID:FabianWe,项目名称:foodle,代码行数:35,代码来源:fields.py

示例2: vote

def vote(request, question_id):

    response_json = {}
    if request.method == 'POST':
        form = RadioVoteForm(request.POST)
        if form.is_valid():
            p = get_object_or_404(Question, pk=question_id)
            try:
                selected_choice = p.choice_set.get(pk=request.POST['choice'])
            except (KeyError, Choice.DoesNotExist):
                response_json['error'] = "You didn't select a choice."
            else:
                selected_choice.votes += 1
                selected_choice.save()
                response_json['status'] = 1
                response_json['new_cptch_key'] = CaptchaStore.generate_key()
                response_json['new_cptch_image'] = captcha_image_url(response_json['new_cptch_key'])
        else:
            response_json['status'] = 0
            response_json['form_errors'] = form.errors
            response_json['new_cptch_key'] = CaptchaStore.generate_key()
            response_json['new_cptch_image'] = captcha_image_url(response_json['new_cptch_key'])
            print >>sys.stderr, 'VOTE FORM ERROR: ' + str(form.errors)
    else:
        response_json['error'] = "Method is not POST"
    return HttpResponse(json.dumps(response_json), content_type="application/json")
开发者ID:MichaelProkofyev,项目名称:Bastionride,代码行数:26,代码来源:views.py

示例3: setUp

 def setUp(self):
     CaptchaStore.generate_key()
     self.hashkey = CaptchaStore.objects.all()[0].hashkey
     self.response = CaptchaStore.objects.all()[0].response
     self.user = User.objects.create_user(username='user_exist',
                                          email='[email protected]',
                                          password='glass_onion')
开发者ID:tethysplatform,项目名称:tethys,代码行数:7,代码来源:test_utilities.py

示例4: login

def login(request):  
    #刷新验证码
    if request.GET.get('newsn')=='1':
        csn=CaptchaStore.generate_key()
        cimageurl= captcha_image_url(csn)
        return HttpResponse(cimageurl)

    t = loader.get_template('backstage/login.html')  
    c = RequestContext(request, {'foo': 'bar'})

    if request.POST:
        form = CaptchaTestForm(request.POST)

        # Validate the form: the captcha field will automatically
        # check the input
        if form.is_valid():
            human = True

        to_json_response = dict()
        to_json_response['status'] = 0
        to_json_response['form_errors'] = form.errors

        to_json_response['new_cptch_key'] = CaptchaStore.generate_key()
        to_json_response['new_cptch_image'] = captcha_image_url(to_json_response['new_cptch_key'])

        return HttpResponse(json.dumps(to_json_response), content_type='application/json')

    else:
        form = CaptchaTestForm()  

        #return HttpResponse(t.render(c))
        #return render_to_response('backend/login.html',locals())
        return render_to_response('backstage/login.html',
            locals(),
            context_instance=RequestContext(request, processors=[]))
开发者ID:fffy2366,项目名称:django-chshtv,代码行数:35,代码来源:backstage.py

示例5: handle

 def handle(self, **options):
     verbose = int(options.get('verbosity'))
     count = options.get('pool_size')
     CaptchaStore.create_pool(count)
     verbose and self.stdout.write('Created %d new captchas\n' % count)
     options.get('cleanup_expired') and CaptchaStore.remove_expired()
     options.get('cleanup_expired') and verbose and self.stdout.write('Expired captchas cleaned up\n')
开发者ID:RDXT,项目名称:django-simple-captcha,代码行数:7,代码来源:captcha_create_pool.py

示例6: test_empty_pool_fallback

 def test_empty_pool_fallback(self):
     __current_test_get_from_pool_setting = settings.CAPTCHA_GET_FROM_POOL
     settings.CAPTCHA_GET_FROM_POOL = True
     CaptchaStore.objects.all().delete()  # Delete objects created during SetUp
     with LogCapture() as l:
         CaptchaStore.pick()
     l.check(('captcha.models', 'ERROR', "Couldn't get a captcha from pool, generating"),)
     self.assertEqual(CaptchaStore.objects.count(), 1)
     settings.CAPTCHA_GET_FROM_POOL = __current_test_get_from_pool_setting
开发者ID:RDXT,项目名称:django-simple-captcha,代码行数:9,代码来源:tests.py

示例7: clean

 def clean(self, value):
     super(CaptchaField, self).clean(value)
     response, value[1] = value[1].strip().lower(), ''
     CaptchaStore.remove_expired()
     try:
         store = CaptchaStore.objects.get(response=response, hashkey=value[0], expiration__gt=datetime.datetime.now())
     except Exception:
         raise ValidationError(getattr(self,'error_messages',dict()).get('invalid', _('Invalid CAPTCHA')))
     return value
开发者ID:dpetzold,项目名称:django-simple-captcha,代码行数:9,代码来源:fields.py

示例8: clean

 def clean(self, value):
     super(CaptchaField, self).clean(value)
     response, value[1] = value[1].strip().lower(), ''
     CaptchaStore.remove_expired()
     try:
         store = CaptchaStore.objects.get(response=response, hashkey=value[0], expiration__gt=get_safe_now())
         store.delete()
     except Exception:
         raise ValidationError(getattr(self, 'error_messages', dict()).get('invalid', _(u'.کد امنیتی وارد شده صحیح نمی باشد')))
     return value
开发者ID:AlirezaSadeghi,项目名称:Juck,代码行数:10,代码来源:persian_captcha.py

示例9: clean

 def clean(self, value):
     super(CaptchaField, self).clean(value)
     response, value[1] = value[1].strip().lower(), ''
     CaptchaStore.remove_expired()
     try:
         store = CaptchaStore.objects.get(response=response,hashkey=value[0], expiration__gt=datetime.datetime.now())
         store.delete()
     except Exception:
         raise ValidationError('Error')
     return value
开发者ID:Crackpot,项目名称:gftop,代码行数:10,代码来源:fields.py

示例10: validate

 def validate(self, attrs):
     response = (attrs.get('response') or '').lower()
     hashkey = attrs.get('hashkey', '')
     CaptchaStore.remove_expired()
     if not self.required and not response:
         pass
     else:
         try:
             CaptchaStore.objects.get(response=response, hashkey=hashkey, expiration__gt=get_safe_now()).delete()
         except CaptchaStore.DoesNotExist:
             raise ValidationError(self.error_messages['invalid_captcha'])
     return {}
开发者ID:sinitsynsv,项目名称:djangorestframework-simple-captcha,代码行数:12,代码来源:fields.py

示例11: clean

 def clean(self, value):
     super(CaptchaField, self).clean(value)
     response, value[1] = value[1].strip().lower(), ""
     CaptchaStore.remove_expired()
     try:
         store = CaptchaStore.objects.get(
             response=response, hashkey=value[0], expiration__gt=datetime.datetime.now()
         )
         store.delete()
     except Exception:
         raise ValidationError(u"Введённый текст не совпадает с текстом на картинке")
     return value
开发者ID:vden,项目名称:TsoguNG,代码行数:12,代码来源:fields.py

示例12: post

    def post(self, request):
        result = {}
        (check_sign_result, check_code, check_msg) = check_sign(request)
        if not check_sign_result:
            result['code'] = check_code
            result['msg'] = check_msg
            return Response(result)
        try:
            mobile = request.POST.get('mobile', '')
            if not local_mobile_phone_validator(mobile):
                msg = u'手机号码不合法。'
                result['code'] = 234
                result['msg'] = msg
                return Response(result)
            else:
                try:
                    userprofile = UserProfile.objects.get(mobile_phone=mobile)
                    current_key = CaptchaStore.generate_key()
                    image_url = captcha_image_url(current_key)
                    http_host = request.get_host()
                    img = ''.join(['http://', http_host, image_url])
                    current_store = CaptchaStore.objects.get(hashkey=current_key)
                    img_value = current_store.challenge

                    result['code'] = 199
                    result['msg'] = u'获取图片验证码成功'
                    result['img'] = img
                    result['imgvalue'] = img_value
                except UserProfile.DoesNotExist:
                    result['code'] = 240
                    result['msg'] = u'不存在使用这个手机号的用户'
            return Response(result)
        except Exception, e:
            traceback.print_exc()
            return Response({'msg': u'获取图片验证码失败', 'code': 238})
开发者ID:lisongwei1593,项目名称:demo,代码行数:35,代码来源:views.py

示例13: resend_activation_link

def resend_activation_link(request):
    if Site._meta.installed:
        site = Site.objects.get_current()
    else:
        site = RequestSite(request)

    if request.method == 'POST' and request.is_ajax():
        captcha_key = CaptchaStore.generate_key()
        captcha_image = captcha_image_url(captcha_key)
        form = ResendActivationEmailForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data["email"]
            users = get_user_model().objects.filter(email=email, is_active=False)
            if not users.count():
                form._errors["email"] = (_("Account for email address is not registered or already activated."),)
            else:
                for user in users:
                    for profile in RegistrationProfile.objects.filter(user=user):
                        if profile.activation_key_expired():
                            salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
                            profile.activation_key = hashlib.sha1(salt + user.username).hexdigest()
                            profile.save()
                            user.date_joined = timezone.now()
                            user.save()
                        profile.send_activation_email(site)

                # messages.add_message(request, messages.INFO, _('Resend activation link done'))
                return ajaxResponse(False, response_header=_('Resend activation link done'), captcha_key=captcha_key,
                                    captcha_image=captcha_image)
        return ajaxResponse(True, form=form, captcha_key=captcha_key, captcha_image=captcha_image)

    form = ResendActivationEmailForm()
    return render(request, "registration/resend_activation_email_form.html", {"form": form})
开发者ID:dhootha,项目名称:akenergo,代码行数:33,代码来源:views.py

示例14: forgot_passwd

def forgot_passwd(request):
    if request.method == "POST":
        if not request.is_ajax():
            raise Http404
        result={}
        passwd = request.POST.get('passwd', '')
        telcode = request.POST.get("code", '')
        mobile = request.POST.get('mobile', '')
        if not (passwd and telcode and mobile):
            result['code'] = '3'
            result['res_msg'] = u'传入参数不足!'
            return JsonResponse(result)
        ret = verifymobilecode(mobile,telcode)
        if ret != 0:
            result['code'] = 1
            if ret == -1:
                result['res_msg'] = u'请先获取手机验证码'
            elif ret == 1:
                result['res_msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['res_msg'] = u'手机验证码已过期,请重新获取'
        else:
            user = MyUser.objects.get(mobile=mobile)
            user.set_password(passwd)
            user.save(update_fields=["password"])
            result['code'] = 0
        return JsonResponse(result)
    else:
        hashkey = CaptchaStore.generate_key()
        codimg_url = captcha_image_url(hashkey)
        return render(request,'registration/forgot_passwd.html',
                  {'hashkey':hashkey, 'codimg_url':codimg_url})
开发者ID:csdusunlight,项目名称:dragon,代码行数:32,代码来源:forgot_passwd.py

示例15: refresh_captcha

def refresh_captcha(request):
    """
    刷新验证码图片
    """
    new_key = CaptchaStore.generate_key()
    new_img = captcha_image_url(new_key)
    return HttpResponse(new_img)
开发者ID:kliyes,项目名称:kblog,代码行数:7,代码来源:views.py


注:本文中的captcha.models.CaptchaStore类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。