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.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 shopinsert(request): try: ob = Users() ob.username = request.POST['username'] ob.name = '请输入用户名' #获取密码并md5 import hashlib m = hashlib.md5() m.update(bytes(request.POST['password'], encoding="utf8")) ob.password = m.hexdigest() ob.sex = 1 ob.address = '北京' ob.code = 0 ob.phone = 0 ob.email = '100000' ob.state = 1 ob.addtime = time.time() ob.save() context = {'info': '添加成功!'} except: context = {'info': '添加失败!'} return render(request, "myweb/shoplogin.html", context)
def userinsert(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=1 a.addtime=time.time() a.save() context = {'info':'添加成功请登录'} return render(request,'myweb/login.html',context) except: context={'info':'添加失败'} return render(request,'myweb/add.html',context)