Пример #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)
Пример #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)
Пример #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)
Пример #4
0
def doregister(request):
    try:
        user = Users.objects.all()
        if user.filter(username=request.POST['username']):
            context = {'info': '此用户名已经注册!'}
        else:
            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()
            if request.POST['password'] == request.POST['repassword']:
                ob.address = request.POST['address']
                ob.email = request.POST['email']
                ob.phone = request.POST['phone']
                ob.code = request.POST['code']
                ob.addtime = time.time()
                ob.save()
                return render(request, "myweb/login.html")
            else:
                context = {'info': '请重新确认密码!'}
            return render(request, "myweb/register.html", context)
    except:
        context = {'info': '注册失败啦!'}
    return render(request, "myweb/info.html", context)
Пример #5
0
def user_insert(request):
    from django.contrib.auth.hashers import make_password
    # list1 = ['username', 'password', 'phone', 'email', 'address', 'age', 'sex', 'status']
    res = request.POST
    try:
        uname = res['username']
        user_a = Users()
        user_a.username = res['username']
        user_a.password = make_password(res['password'], None, 'pbkdf2_sha256')
        user_a.phone = res['phone']
        user_a.email = res['email']
        user_a.address = res['address']
        user_a.age = res['age']

        if res['sex'] in ('0', '1'):
            user_a.sex = res['sex']
        else:
            a = '\033[1;31mERROR: \033[1;34m文件:%s\033[1;31m 年龄字段 插入 error , 插入价值不是男或女\033[0m' % (
                MYADMAIN_USER_V1)
            print(a)
            raise AttributeError("年龄字段 插入 error , 插入价值不是男或女, %s" % a)
        if res['status'] in ('0', '1', '2'):
            user_a.status = res['status']
        else:
            b = '\033[1;31mERROR: \033[1;34m文件:%s\033[1;31m 状态字段 插入 error, 插入值不正确\033[0m' % (
                MYADMAIN_USER_V1)
            print(b)
            raise AttributeError("状态字段 插入 error, 插入值不正确, %s" % b)

        # user_a.status = res['status']
        if request.FILES.get('pic', None):
            user_a.pic = filesload(request, uname)
        user_a.save()
        return HttpResponse(
            '<script>alert("添加成功");location.href="/myadmin/user_index"</script>'
        )
    except AttributeError as arterror:
        return HttpResponse(
            '<script>alert("添加失败, 图片上传错误, 请重新添加");location.href="/myadmin/useradd"</script>'
        )
    except BaseException as be:
        return HttpResponse(
            '<script>alert("添加失败, 字段指定错误请重新制定");location.href="/myadmin/useradd"</script>'
        )
Пример #6
0
    def post(self, request):
        try:
            from django.contrib.auth.hashers import make_password
            res = request.POST
            list1 = [
                'username', 'password', 'phone', 'email', 'address', 'age',
                'sex'
            ]
            for i in list1:
                if not res.get(i):
                    print(res.get(i))
                    return HttpResponse(
                        '<script>alert("字段为空, 无法添加");location.href="/register/"</script>'
                    )
            print('username_res', res.get('username'))
            users_name = Users.objects.filter(username=res.get('username'))
            print(users_name)
            if len(users_name) != 0:
                return HttpResponse(
                    '<script>alert("用户名已存在, 请重新添加");location.href="/register/"</script>'
                )

            user_a = Users()
            user_a.username = res['username']
            user_a.password = make_password(res['password'], None,
                                            'pbkdf2_sha256')
            user_a.phone = res['phone']
            user_a.email = res['email']
            user_a.address = res['address']
            user_a.age = res['age']
            user_a.sex = res['sex']
            user_a.status = 1
            user_a.save()
            request.session['login_status'] = True
            request.session['login_users'] = {
                'user_id': user_a.id,
                'username': user_a.username
            }
        except:
            return HttpResponse(
                '<script>alert("表单信息不正确, 请重新添加");location.href="/register/"</script>'
            )
        return redirect(reverse('home_index'))
Пример #7
0
def insertuser(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.code = request.POST['code']
        ob.phone = request.POST['phone']
        ob.email = request.POST['email']
        ob.status = request.POST['status']
        ob.addtime = time.time()
        ob.save()
        context = {'info': '添加成功!'}
    except:
        context = {'info': '添加失败!'}
    return render(request, "myadmin/info.html", context)
Пример #8
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)
Пример #9
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>")
Пример #10
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)
Пример #11
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)
Пример #12
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'], 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': '添加成功!'}
    except:
        context = {'info': '添加失败!'}
    return render(request, 'myadmin/info.html', context)