Ejemplo n.º 1
0
def getCheck(requests):
    id = str(randint(1, 10000000))
    value = str(randint(1, 100) * randint(1, 100))
    date = int(time())
    c = Check(checkId=id, checkValue=value, checkDate=date)
    c.save()
    req = {'message': 'success', 'content': (id, value, date)}
    return HttpResponse(dumps(req), content_type="application/json")
Ejemplo n.º 2
0
def getCheck(requests):
    id=str(randint(1,10000000))
    a=randint(1,100)
    b=randint(1,100)
    value=str(a*b)
    date=int(time())
    c=Check(checkId=id,checkValue=value,checkDate=date)
    c.save()
    req={'message':'success','content':('id':id,'value':str(a)+'*'+str(b))}
Ejemplo n.º 3
0
def getCheck(requests):
    id=str(randint(1,10000000))
    a=randint(1,100)
    b=randint(1,100)
    value=str(a*b)
    date=int(time())
    c=Check(checkId=id,checkValue=value,checkDate=date)
    c.save()
    req={'message':'success','content':{'id':id,'value':str(a)+'*'+str(b)}}
    return HttpResponse(dumps(req),content_type="application/json")
Ejemplo n.º 4
0
def getCheck(requests):
    id=str(randint(1,10000000))
    a=randint(1,100)
    b=randint(1,100)
    value=str(a*b)
    date=int(time())
    c=Check(checkId=id,checkValue=value,checkDate=date)
    c.save()
    req={'message':'success','content':{'id':id,'value':str(a)+'*'+str(b)}
    return HttpResponse(dumps(req),content_type="application/json")

@csrf_exempt
def checkCheck(requests):
    if requests.method=='POST':
        try:
            id=requests.POST['checkId']
            value=requests.POST['checkValue']
        except:
            req={'message':'fall','content':"验证码错误"}
            return HttpResponse(dumps(req),content_type="application/json")
        try:
            c=Check.objects.get(checkId=id)
            print('获取check对象成功..')
        except:
            print('id号不存在..')
            req={'message':'fall','content':"验证码错误"}
            return HttpResponse(dumps(req),content_type="application/json")
        if int(time())-c.checkDate<=70000:
            if c.checkValue==value:
                print('验证码正确..')
                c.checkDate=1000000   #验证码正确就设置时间为很早以前
                c.save()
                req={'message':'true','content':"验证码正确"}
                return HttpResponse(dumps(req),content_type="application/json")
            else:
                print('验证码对不上号..')
                req={'message':'fall','content':"验证码错误"}
                return HttpResponse(dumps(req),content_type="application/json")
        else:
            print('超时了...')
            req={'message':'fall','content':"验证码错误"}
            return HttpResponse(dumps(req),content_type="application/json")
    else:
        req={'message':'fall','content':"验证码错误"}
        return HttpResponse(dumps(req),content_type="application/json")