def insert(request): try: user = Users() user.username = request.POST['username'] user.name = request.POST['name'] import hashlib md5 = hashlib.md5() #md5对象,md5不能反解,但是加密是固定的,就是关系是一一对应,所以有缺陷,可以被对撞出来 md5.update(bytes(request.POST['password'], encoding='utf-8')) #要对哪个字符串进行加密,就放这里 user.password = md5.hexdigest() #拿到加密字符串 print(f"md5加密之后的结果:{user.password}") user.sex = request.POST['sex'] user.address = request.POST['address'] user.code = request.POST['code'] user.phone = request.POST['phone'] user.email = request.POST['email'] user.state = '1' user.addtime = datetime.now().strftime("%Y-%m-%d %H:%H:%S") user.save() print(user.addtime) context = {'info': '会员添加成功!'} except Exception as err: context = {'info': '会员添加失败!'} print(f"添加失败的原因是:{err}") return render(request, './myadmin/users/info.html', context)
def insert(httpRequest): '''执行添加''' try: mod = Users() mod.username = httpRequest.POST.get('username',None) mod.name = httpRequest.POST.get('name',None) # mod.password = httpRequest.POST.get('password',None) #获取密码并md5 m = hashlib.md5() m.update(bytes(httpRequest.POST['password'],encoding="utf8")) mod.password = m.hexdigest() mod.sex = httpRequest.POST.get('sex',None) mod.address = httpRequest.POST.get('address',None) mod.phone = httpRequest.POST.get('phone',None) mod.email = httpRequest.POST.get('email',None) mod.state = 1 mod.code = httpRequest.POST.get('code',None) mod.save() data = {"info":'添加成功'} except Exception as e: print(e) data = {"info":'账号已被注册添加!'} return render(httpRequest,'myadmin/info.html',data) return render(httpRequest,'myadmin/info.html',data)
def insert(request): try: ob = Users() ob.username = request.POST['username'] ob.name = request.POST['name'] #获取密码并md5 import hashlib if request.POST['password'] == request.POST['repassword']: 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 = datetime.now().strftime("%Y-%m-%d %H:%M:%S") ob.save() context = {'info': '添加成功!'} else: context = {'info': '2次密码输入不一致!'} except Exception as err: print(err) context = {'info': '添加失败!'} return render(request, "myadmin/info.html", context)
def insert(request): '''添加数据''' try: ob = Users() ob.username = request.POST['username'] ob.name = request.POST['name'] ob.password = request.POST['password'] ob.repassword = request.POST['repassword'] if ob.password != ob.repassword: context = {"info": "两次密码不符"} else: # 获取密码并md5 import hashlib m = hashlib.md5() m.update(bytes(ob.password, encoding="utf8")) ob.password = m.hexdigest() # 调用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 = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # 格式化时间 ob.save() context = {'info': '添加成功'} except Exception as err: context = {"info": '添加失败'} return render(request, 'myadmin/info.html', context)
def doregister(request): ''' 执行注册 :param request: :return: ''' # 判断用户名是否已注册 try: username = request.POST["username"] user = Users.objects.filter(username=username) if user: context = {"info": "该账号已注册"} return render(request, "web/useregister.html", context) user = Users() user.username = username user.name = request.POST["name"] user.password = encryptionUtil.getencodepassword( request.POST["password"]) user.sex = request.POST["sex"] user.code = request.POST["code"] user.address = request.POST["address"] user.state = 1 user.phone = request.POST["phone"] user.email = request.POST["email"] user.save() request.session["vipuser"] = user.toDict() return redirect(reverse("index")) except Exception as err: print(err) context = {"info": "注册信息异常"} return render(request, 'web/useregister.html', context)
def insert(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.address = request.POST['address'] ob.code = request.POST['code'] ob.phone = request.POST['phone'] ob.email = request.POST['email'] ob.state = 1 # ob.addtime=datetime.now().strftime("%Y-%m-%d %H:%M:%S") # ob.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S") ob.save() context = {"info": "添加成功"} except Exception as err: print(err) context = {"info": "添加失败"} return render(request, 'myadmin/info.html', context)
def insert(request): try: #新增会员信息 list = Users() list.username = request.POST['txt_user'] #获取密码并md5 import hashlib m = hashlib.md5() m.update(bytes(request.POST['password'], encoding="utf8")) list.password = m.hexdigest() list.name = request.POST['txt_name'] list.sex = request.POST['ra_sex'] list.state = request.POST['ra_rob'] list.address = request.POST['txt_addr'] list.code = request.POST['txt_map'] list.phone = request.POST['txt_phone'] list.email = request.POST['txt_mail'] list.save() info = "保存成功!" mypic = request.FILES.get('txt_photo', None) if not mypic: info += "照片为空。" else: if mypic.name.split(".").pop() == 'png': img = Image.open(mypic) filename = str(request.POST['txt_user']) + '.jpg' if len(img.split()) == 4: #将图片png格式统一成jpg r, g, b, a = img.split() img = Image.merge("RGB", (r, g, b)) img.save("./static/mymanage/tempimg/" + filename) else: filename = str( request.POST['txt_user']) + '.' + mypic.name.split( ".").pop() #time.time() destination = open("./static/mymanage/tempimg/" + filename, "wb+") #图片多用wb+代表二进制操作,其他的可以使用W或者w+ for chunk in mypic.chunks(): # 分块写入文件 destination.write(chunk) destination.close() info += "并有个人照片。" context = {"info": info} return render(request, "mymanage/info.html", context) except Exception as info: context = {"info": info} return render(request, "mymanage/info.html", context)
def userinsert(request): try: user = Users() user.name = request.POST["name"] user.username = request.POST['username'] user.email = request.POST["email"] user.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S") user.sex = request.POST["sex"] user.phone = request.POST["phone"] user.code = request.POST["code"] user.address = request.POST["address"] user.state = 1 user.password = encryptionUtil.getencodepassword( request.POST["password"]) user.save() context = {"info": "添加用户信息成功"} except Exception as err: context = {"info": "添加用户信息失败"} print(err) return render(request, "console/users/edit.html", context)
def insert(httpRequest): '''信息注册''' very = httpRequest.POST.get('code',None) if very!=httpRequest.session.get('verifycode'): data = {"info":'验证码信息错误'} return render(httpRequest,'web/registor.html',data) try: mod = Users() username = httpRequest.POST.get('username',None) name = httpRequest.POST.get('name',None) psd = httpRequest.POST.get('password',None) if (not username) or (not name) or (not psd): data = {"info":'请把信息填写完整'} return render(httpRequest,'web/registor.html',data) psd1 = httpRequest.POST.get('password1',None) if psd != psd1: data = {"info":'密码输入不一致'} return render(httpRequest,'web/registor.html',data) #获取密码并md5 m = hashlib.md5() m.update(bytes(psd,encoding="utf8")) mod.password = m.hexdigest() mod.username = username mod.name = name mod.sex = httpRequest.POST.get('sex',"-1") mod.address = httpRequest.POST.get('address',"") mod.phone = httpRequest.POST.get('phone',"") mod.email = httpRequest.POST.get('email',"") mod.state = 1 mod.code = "" mod.save() data = {"info":'注册成功'} except Exception as e: print(e) data = {"info":'账号已被注册添加!'} return render(httpRequest,'web/registor.html',data) return render(httpRequest,'web/registor.html',data)