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): '''执行添加''' #根据账号获取登录者信息 user = Users.objects.get(id=request.session['volunteers']['id']) 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.student_id = request.POST['student_id'] 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": "添加成功!", "state": user.state} except Exception as err: print(err) context = {"info": "添加失败", "state": user.state} return render(request, "myadmin/info.html", context)
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 doregister(request): # 获取注册信息 username = request.POST.get('username') password = request.POST.get('password') repassword = request.POST.get('repassword') # 判断两次密码输入是否一致 if password != repassword: context = {"info": "密码输入不一致"} return render(request, "web/register.html", context) else: try: # 判断用户是否存在 count = Users.objects.filter(phone=username).count() print(count) if count > 0: context = {"info": "用户已存在"} return render(request, "web/register.html", context) else: # 添加数据进入模型 user = Users() user.phone = username user.username = username # 密码处理 import hashlib m = hashlib.md5() m.update(bytes(password, encoding='utf8')) user.password = m.hexdigest() user.save() # 完成后跳转至登录页面 context = {"info": "注册完成,请登录"} return render(request, "web/login.html", context) except Exception as e: context = {"info": "注册失败" + e} return render(request, "web/register.html", context)
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 regupdate(request): #判断两次密码是否一致 pwd = request.POST['passwd'] repwd = request.POST['repasswd'] name = request.POST['username'] if Users.objects.filter(username=name): content = {'info': '用户名已被注册'} else: if repwd != pwd: content = {"info": "两次密码不相同,请重新输入!"} return render(request, "web/register.html", content) try: gb = Users() gb.username = request.POST['username'] import hashlib m = hashlib.md5() m.update(bytes(request.POST['passwd'], encoding="utf8")) gb.password = m.hexdigest() gb.email = request.POST['email'] gb.phone = request.POST['phone'] gb.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S") gb.state = 1 gb.save() content = {"info": "注册成功!可以登录了"} return render(request, "web/register.html", content) except: content = {"info": "注册失败!"} return render(request, "web/register.html", content)
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 insert(request): try: ob = Users() ob.username = request.POST['username'] ob.name = request.POST['name'] passw = request.POST['password'] dj_ps = make_password(passw, None, 'pbkdf2_sha256') #加密 ob.password = dj_ps 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: print(err) context = {'info': '保存失败!'} return render(request, 'myadmin/info.html', context)
def insert(request): '''执行会员信息添加''' try: ob = Users() ob.username = request.POST['account'] #获取密码并md5 import hashlib m = hashlib.md5() m.update(bytes(request.POST['password'],encoding="utf8")) ob.password = m.hexdigest() ob.phone = request.POST['account'] ob.state = 1 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,"web/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)
def insert(request): """执行添加""" try: ob = Users() # 实例化Users模型 ob.username = request.POST['registerUsername'] # 密码md5加密 import hashlib m = hashlib.md5() m.update(bytes(request.POST['registerPassword'], encoding='utf-8')) ob.password = m.hexdigest() ob.sex = request.POST['gender'] ob.email = request.POST['registerEmail'] ob.phone = request.POST['registerPhone'] ob.state = 1 ob.addtime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') ob.save() # 将数据存储至数据库 return redirect('/users') except Exception as err: print(err) context = {'Info': 'Addition Failed', 'Detail': err} return render(request, 'backstage/info.html', context)