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)
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)
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)
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)
def do_register(request): if request.POST['password'] != request.POST['repassword']: return JsonResponse({'msg': 'passwd_error'}) elif Users.objects.filter(username=request.POST['username']): return JsonResponse({'msg': 'account_error'}) else: users = Users() users.username = request.POST['username'] md5 = hashlib.md5() md5.update(bytes(request.POST['password'], encoding='UTF-8')) # 十六进制保存到数据库 users.password = md5.hexdigest() users.name = request.POST['name'] users.mobile = request.POST['mobile'] users.address = request.POST['address'] users.save() return JsonResponse({'msg': 'success'})
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)
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)
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)
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)
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)
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)
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)