Exemple #1
0
def zhucego(request):
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']
        if request.POST['password'] == request.POST['repassword']:

            #获取密码并md5
            import hashlib
            m = hashlib.md5()
            m.update(bytes(request.POST['password'], encoding="utf8"))
            ob.password = m.hexdigest()
            ob.sex = request.POST['sex']
            ob.address = request.POST['address']
            ob.code = request.POST['code']
            ob.phone = request.POST['phone']
            ob.email = request.POST['email']
            ob.state = 1
            ob.addtime = time.time()
            ob.save()
            context = {'info': '添加成功!'}
        else:
            context = {'info': '密码不一致'}
    except:
        context = {'info': '添加失败!'}

    #return render(request,"myadmin/info.html",context)
    return render(request, "myweb/info.html", context)
Exemple #2
0
def users_insert(request):
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']
        if request.POST['password'] == request.POST['repassword']:
            #获取密码并m5d
            import hashlib
            m = hashlib.md5()
            m.update(bytes(request.POST['password'], encoding='utf8'))
            ob.password = m.hexdigest()
            ob.sex = request.POST['sex']
            ob.address = request.POST['address']
            ob.code = request.POST['code']
            ob.phone = request.POST['phone']
            ob.email = request.POST['email']
            ob.state = 1
            ob.addtime = time.time()
            ob.save()
            context = {'info': '添加成功!'}
        else:
            return redirect(reverse('myadmin_uadd'))
    except:
        context = {'info': '添加失败'}
    return render(request, 'myadmin/info.html', context)
Exemple #3
0
def usersinsert(request):
    """
    添加会员信息

    :param request:
    """
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']
        # 获取密码, 用md5加密
        m = hashlib.md5()
        m.update(bytes(request.POST['password'], encoding='utf8'))
        ob.password = m.hexdigest()
        ob.sex = request.POST['sex']
        ob.address = request.POST['address']
        ob.code = request.POST['code']
        ob.phone = request.POST['phone']
        ob.email = request.POST['email']
        ob.state = 1
        ob.save()
        context = {'info': '修改成功! '}
    except:
        context = {'info': '修改失败! '}
    return render(request, 'myadmin/info.html', context)
Exemple #4
0
def usersinsert(request):
	try:
		a=Users()
		a.username=request.POST["username"]
		a.name=request.POST['name']
		import hashlib
		m=hashlib.md5()
		m.update(bytes(request.POST['password'],encoding='utf8'))
		a.password=m.hexdigest()
		a.sex=request.POST['sex']
		a.address=request.POST['address']
		a.code=request.POST['code']
		a.phone=request.POST['phone']
		a.email=request.POST['email']
		a.state=request.POST['state']
		a.addtime=time.time()
		a.save()
		context={'info':'添加成功'}
	except:
		context={'info':'添加失败'}
	return render(request,'myadmin/info.html',context)
Exemple #5
0
def insertregedit(request):
    try:
        ob = Users()
        ob.username = request.POST.get('name')
        from django.contrib.auth.hashers import make_password
        ob.password = make_password(request.POST.get('password'), None,
                                    'pbkdf2_sha256')
        aa = request.POST.get('password2')
        ob.email = request.POST.get('email')
        ob.state = request.POST.get('state')
        if not request.FILES.get('img'):
            ob.img = 'static/public/img/9110.jpg'
        else:
            ob.img = request.FILES.get('img')

        ob.save()
        return HttpResponse(
            "<script>alert('注册成功');location.href='/user/index'</script>")
    except:
        return HttpResponse(
            "<script>alert('注册失败');location.href='/user/index'</script>")
Exemple #6
0
def usersinsert(request):
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']

        # 获取密码并md5
        import hashlib
        m = hashlib.md5()
        # update函数要求参数是bytes
        m.update(bytes(request.POST['password'], encoding="utf8"))
        ob.password = m.hexdigest()
        ob.gender = request.POST['sex']
        ob.address = request.POST['address']
        ob.state = 1
        ob.save()
        context = {"info":"添加成功"}
    except:
        context = {"info":"添加失败"}

    return render(request, "myadmin/info.html", context)
Exemple #7
0
def adminInsert(request):
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['password'], encoding="utf8"))
        ob.password = m.hexdigest()
        ob.sex = request.POST['sex']
        ob.adress = request.POST['adress']
        ob.code = request.POST['code']
        ob.phone = request.POST['phone']
        ob.email = request.POST['email']
        ob.state = request.POST['state']
        ob.addtime = request.POST['addtime']
        ob.save()
        context = {'info': '添加成功'}
    except:
        context = {'info': '添加失败'}
    return render(request, "myadmin/users/info.html", context)
Exemple #8
0
def do_useradd(request):
    # 添加try的原因:
    # 防止发生内部错误:例如外键冲突,字段唯一性等
    try:
        us = Users()
        us.username = request.POST['username']
        # 实例化md5实例
        md5 = hashlib.md5()
        # python3中md5只能加密字节型数据,所以要用bytes强制转换
        md5.update(bytes(request.POST['password'],encoding="utf-8"))
        us.password = md5.hexdigest()
        us.name = request.POST['name']
        us.gender = request.POST['sex']
        us.mobile = request.POST['mobile']
        us.address = request.POST['address']
        us.state = 0
        us.status = 0
        us.save()
        context = {"info":"添加成功"}
    except:
        context = {"info": "添加失败"}
    return render(request, "myadmin/info.html", context)
Exemple #9
0
def usersinsert(request):
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']
        # 获取密码并md5
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['password']))
        ob.password = m.hexdigest()
        ob.sex = request.POST['sex']
        ob.address = request.POST['address']
        ob.code = request.POST['code']
        ob.phone = request.POST['phone']
        ob.email = request.POST['email']
        ob.state = 1
        ob.addtime = time.time()
        ob.save()
        context = {'info': '添加成功!'}
    except:
        context = {'info': '添加失败!'}

    return render(request, "myadmin/info.html", context)
Exemple #10
0
def zcinsert(request):
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']
        # 进行加密
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['passwd'], encoding="utf8"))
        ob.passwd = m.hexdigest()

        ob.sex = request.POST['sex']
        ob.address = request.POST['address']
        ob.code = 220077
        ob.phone = request.POST['phone']
        ob.email = request.POST['email']
        ob.state = 1
        ob.addtime = time.time()
        ob.save()
        context = {'info': '添加成功'}
    except:
        context = {'info': '添加失败'}
    return render(request, 'myadmin/info.html', context)