Example #1
0
def usr_login(request):
    # 生成验证码图片和正确的验证码
    img, right_code = gvcode.base64()
    # 将正确的验证码存到内存中名叫:right_code
    request.session['right_code'] = right_code
    # 返回渲染验证码图片
    return HttpResponse(img)
Example #2
0
def get_code(request):
    base64_str, code = gvcode.base64()

    # 把code存到session中
    request.session['verify_code'] = code
    # 把base64_str 返回给用户
    return HttpResponse(base64_str)
Example #3
0
def get_code():
    base64_str, code = gvcode.base64()

    # 把code存到session中
    session['verify_code'] = code
    # 把base64_str 返回给用户
    return str(base64_str, "utf-8")
Example #4
0
File: views.py Project: duzie0/blog
def get_code(request):
    base64_code, str_code = gvcode.base64()
    resp_date = {}
    bc = str(base64_code)
    resp_date['base64_code'] = bc
    resp_date['str_code'] = str_code
    return HttpResponse(json.dumps(resp_date))
Example #5
0
    def get(self):
        base64_str, code = gvcode.base64()

        # 把code存到session中
        r.set('verify_code', code)
        print(code)
        # 把base64_str 返回给用户
        return str(base64_str, "utf-8")
Example #6
0
def get_code(request):
    # """
    # 返回一个base64编码的随机验证码
    # """
    base64_code,str_code = gvcode.base64()
    request.session['verify_code'] = str_code      ###!!!!!!!!!!!!!!!
    # return  render(request,'user/login.html',{'base64_code':base64_code})
    return HttpResponse(base64_code)
Example #7
0
def hudonger(request):
    context = {}
    if request.method == 'GET':
        img, right_code = gvcode.base64()
        request.session['right_code'] = right_code
        context['img'] = img
        return render(request, '互动交流2.html', context)
    if request.method == 'POST':
        id_num = request.POST.get('sfzh')
        context['hudongs'] = Opinion.objects.filter(id_num=id_num).order_by('-time')[:5].values('time', 'title', 'replay', 'state')
        context['sta'] = 1
        code = request.POST.get('yzm')
        right_code = request.session['right_code']
        if right_code.lower() != code.lower():
            # 不正确时从新返回新验证码,验证码图片和错误信息
            img, right_code = gvcode.base64()
            request.session['right_code'] = right_code
            return render(request, '互动交流2.html', {'img': img, 'error': '<p style="color:red; font-size: large; " >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;验证码错误,请从新输入!</p>'})
    return render(request, '互动交流2.html', context)
Example #8
0
def hudongyi(request):
    context = {}
    if request.method == 'GET':
        img, right_code = gvcode.base64()
        request.session['right_code'] = right_code
        context['img'] = img
        return render(request, '互动交流1.html', context)
    if request.method == 'POST':
        # form = opinionForm(request.POST)
        title = request.POST['bt']
        name = request.POST.get('xm')
        id_num = request.POST.get('sfzh')
        phone = request.POST.get('dh')
        address = request.POST.get('dz')
        email = request.POST.get('yx')
        content = request.POST.get('nr')
        code = request.POST.get('yzm')
        right_code = request.session['right_code']
        if right_code.lower() != code.lower():
            # 不正确时从新返回新验证码,验证码图片和错误信息
            img, right_code = gvcode.base64()
            request.session['right_code'] = right_code
            return render(request, '互动交流1.html', {'img': img, 'error': '<p style="color:red;" >验证码错误,请从新输入!</p>'})
        if len(title)>50:
            return render(request, '互动交流1.html', {'error': '<p style="color:red;" >标题过长!</p>'})
        if len(name)>16:
            return render(request, '互动交流1.html', {'error': '<p style="color:red;" >姓名过长!</p>'})
        if len(id_num)!=18:
            return render(request, '互动交流1.html', {'error': '<p style="color:red;" >身份证号格式不正确!</p>'})
        if len(phone)!=11:
            return render(request, '互动交流1.html', {'error': '<p style="color:red;" >手机号格式不正确!</p>'})
        if len(address)>50:
            return render(request, '互动交流1.html', {'error': '<p style="color:red;" >地址过长!</p>'})
        if not re.search('^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$', email):
            return render(request, '互动交流1.html', {'error': '<p style="color:red;" >邮箱格式不正确!</p>'})
        if len(content)>2000:
            return render(request, '互动交流1.html', {'error': '<p style="color:red;" >内容过长!</p>'})
        sql = Opinion.objects.create(title=title, name=name, id_num=id_num, phone=phone, address=address, email=email, content=content, state=0)
        if sql is None:
            return render(request, '互动交流1.html', {'error': '<p style="color:red;" >出现错误,请重试!</p>'})
        return render(request, '互动交流1.html', {'error': '<p style="color:red;" >提交成功,请于48小时之后,使用您的身份证号在本网站进行查询!</p>'})
 def test_base64(self):
     b64str, vcode = gvcode.base64()
     assert len(vcode) == 4
Example #10
0
 def get(self, request, *args, **kwargs):
     base64_code, str_code = gvcode.base64()
     request.session['verify_code'] = str_code
     return HttpResponse(base64_code)
Example #11
0
def imgcode():
    b64 = gvcode.base64()
    # return json.dumps({"code": b64[1], "img": str(b64[0], 'utf-8')})
    return json.dumps({"code": b64[1], "img": b64[0]})
Example #12
0
#!/usr/bin/python3
# coding: utf-8

# 安装
# https://github.com/vcodeclub/graphic-verification-code
# pip install graphic-verification-code

import gvcode

gvcode.generate()
gvcode.base64()

# ('iVBORw0KGgoAAAANSUhEUgAAAHgAAAAeCAIAAABoq03CAAACyklEQVR4nN1aO04kMRB9NdoIQUIAEVcgIuAEKyQyUsShIOUmmwEpZyAgG4SI+GRTBB48bn+6XXZ52uxTB6OWXS5XPb+y20PMDAAAEdnfPaOFn+M2VUZcVPb/b0BEbe27ubKDtab2jKvHzFE0ekGXEANGM7Mx1yK9rs0ZNcqVyvwu9Q4nmeWlsUMF79ClESQ12qRxa2JSgEmXmsqu1PhEMTSxFhltXVXyoUiOcFJS438mW7iqnWO9Q+73AJnMueH+XRI5O0qCpbLd2TJmp4X+gYVo82wNJveXlwMHbm9xc7N2Qxpl9UozrdEhRlT7Z1YAcHgIIqjTKMpNZt7ZwfGxJ27lo6jTvyTQBqlw25/LJYjw/o69Pf1wezg7w+enyavvSSebIDXlIqKQB4sFVit9XqcENzpQi1WV6Y8LX6OLtSl6dl+tyoxljeUh5fgWSmAOWX3pmLE0W333QpbvkZbvZTkb34wp7zoKTpJOXwAgwvk5Li7ADGY8PfmrZMS4ihy79dzzbRzjHNXcXXpqaJUrXyVTIou8qWrJMRGOjvD8LHZgzGa7QGPDvtxBUlPKjKBioIOJxB3Lh/6B5e5uc2RwP3D387EpB+6BSyV/5fvoEAcHa5/Mrs7BX4CB6UCHlVAKIphl6m25RMGy1cL0YsbHR5VX0GX0y8s6Ug8Pm1kR4fT0H3NVncyECQrAGG43r67KU2jCvbsLZiyX5b61uFEGglOZVySRlu36eui2dHktInWNKEcnGGd0De/cdee+cRqIr+DKVj0GV3GyqDHj+nrwgcw+9/eTfWPnqdYnlMdHnJzkNnbz64pP+FJkStQxZaHGFHSLYRRfX0A2oaJtXB3I/+Y5FCuBD7ZLqnGZqrRitNWplEx3fm+Q0r39fby9lWz4ep+wCNL8TV4Vhepha4A0bN39JayuDktrbME13jrKr6/CjrMw+jfeOlbiGyMXxYAIZpe8AAAAAElFTkSuQmCC',
#  'QnCg')

def main():
    pass


if __name__ == '__main__':
    main()
Example #13
0
def get_code(request):
    base64_code, str_code = gvcode.base64()
    request.session['str_code'] = str_code
    return HttpResponse(base64_code)