def register(request): if request.method=='GET': return render(request,'mine/register.html') elif request.method=='POST': username=request.POST.get('username') password=request.POST.get('password') name=request.POST.get('name') tel=request.POST.get('tel') arr=request.POST.get('arr') token = generate_token() users=User() users.username=username users.password=password users.name=name users.tel=tel users.arr=arr users.token=token users.save() response=redirect('axf:mine') request.session['token']=users.token return response
def doregister(request): try: # /存储用户信息 username = request.POST.get('username') password = request.POST.get('password') email = request.POST.get('email') phone = request.POST.get('phone') # 这里要用[] icon = request.FILES['icon'] print(password) # 获取摘要 md5 = hashlib.md5() # 将原数据传入进行摘要计算, 元数据需要需要进行二进制格式 md5.update(password.encode('utf-8')) # 获取摘要后的信息 hex 16进制 digest获取摘要输出 # digest()获取到的是二进制的输出 hexdigest() 获取的是16进制输出,16进制可以直接转换成可见字符串 p = md5.hexdigest() print(p) password = p user = User() user.u_name = username user.u_passwd = password user.u_email = email user.u_phone = phone user.u_icon = icon user.save() # 将用户个人信息存储在session里 request.session['username'] = username return redirect(reverse('axf:mine')) except Exception as e: print('注册失败') return HttpResponse('注册失败')
def do_register(request): try: username = request.POST.get('username') password = request.POST.get('password') email = request.POST.get('email') phone = request.POST.get('phone') icon = request.FILES['icon'] print(password) # 获取摘要 md5 = hashlib.md5() # 将原数据传入进行摘要摘要运算 2进制才能转 md5.update(password.encode('utf-8')) # 获取摘要后的信息 hex 16进制的输出 p = md5.hexdigest() print(p) password = p user = User() user.u_name = username user.u_password = password user.u_email = email user.u_phone = phone user.u_icon = icon user.save() # 将用户关键信息 request.session['username'] = username return redirect(reverse('axf:mine')) except Exception as e: print(e) return HttpResponse('注册失败')
def login(request): fromPath = request.GET.get("from") gid = request.GET.get("gid") cid = request.GET.get("cid") sid = request.GET.get("sid") if request.method == "GET": return render(request, "mine/login.html", { "fromPath": fromPath, "gid": gid, "cid": cid, "sid": sid }) else: phone = request.POST.get("username") tokenValue = str(uuid.uuid4()) try: user = User.objects.get(pk=phone) #登陆 user.tokenValue = tokenValue user.save() except User.DoesNotExist as e: #注册 user = User.create(phone, tokenValue) user.save() #将电话号码写入session request.session["phone"] = user.phoneNum if gid: response = redirect("/" + fromPath + "/" + gid + "/" + cid + "/" + sid + "/") else: response = redirect("/" + fromPath + "/") #将token写入cookie response.set_cookie("token", user.tokenValue) return response
def registe(request): if request.method == 'GET': return render(request, 'mine/registe.html') elif request.method == 'POST': # try: user = User() user.account = request.POST.get('account') user.password = genarate_password(request.POST.get('password')) user.name = request.POST.get('name') user.phone = request.POST.get('phone') user.addr = request.POST.get('addr') # user.img = 'axf.png' # # # 头像 imgName = user.account + '.png' imagePath = os.path.join(settings.MEDIA_ROOT, imgName) file = request.FILES.get('icon') with open(imagePath, 'wb') as fp: # 打开文件,以读的形式 for data in file.chunks(): fp.write(data) user.img = imgName user.token = str(uuid.uuid5(uuid.uuid4(), 'register')) # user.token = '1' # user.save() # 状态保持 request.session['token'] = user.token # 重定向 return redirect('axf:mine') # return HttpResponse('注册') # except: # return HttpResponse('注册失败(该用户已被注册)') def checkaccount(request): account = request.GET.get('account') responseData = { 'msg': '账号可用', 'status': 1 # 1标识可用,-1标识不可用 } try: user = User.objects.get(account=account) responseData['msg'] = '账号已被占用' responseData['status'] = -1 return JsonResponse(responseData) except: return JsonResponse(responseData)
def register(request): if request.method == 'GET': # 登录时的验证码图片 # vc = VerifyCode() # vc.generate() # print(vc.code) return render(request, 'mine/register.html') elif request.method == 'POST': email = request.POST.get('email') passowrd = generate_password(request.POST.get('password')) name = request.POST.get('name') # print(email,passowrd,name) #存入数据库 user = User() user.email = email user.password = passowrd user.name = name user.save() #状态保持 token = generate_token() #key-value >> token:userid cache.set(token, user.id, 60 * 60 * 24 * 3) request.session['token'] = token return redirect('axf:mine')
def login(request): if request.method == "GET": if request.is_ajax(): # 生产验证码 strNum = '1234567890' # 随机选取4个值作为验证码 rand_str = '' for i in range(0, 6): rand_str += strNum[random.randrange(0, len(strNum))] msg = "您的验证码是:%s。请不要把验证码泄露给其他人。"%rand_str phone = request.GET.get("phoneNum") # send_sms(msg, phone) #存入session request.session["code"] = rand_str print("***************", rand_str) response = JsonResponse({"data":"ok"}) return response else: return render(request, "mine/login.html") else: phone = request.POST.get("username") passwd = request.POST.get("passwd") code = request.session.get("code") if passwd == code: #验证码验证成功 #判断用户是否存在 uuidStr = str(uuid.uuid4()) try: user = User.objects.get(pk=phone) user.tokenValue = uuidStr user.save() except User.DoesNotExist as e: #注册 user = User.create(phone,None,uuidStr,"sunck good") user.save() request.session["phoneNum"] = phone response = redirect("/mine/") # 将tokenValue写入cookie response.set_cookie("token", uuidStr) return response else: # 验证码验证失败 return redirect("/login/")
def register(request): if request.method == 'GET': return render(request, 'mine/register.html') elif request.method == 'POST': email = request.POST.get('email') name = request.POST.get('name') passoword = generate_password(request.POST.get('password')) user = User() user.email = email user.password = passoword user.name = name user.save() token = generate_token() cache.set(token, user.id, 60 * 60 * 24) request.session['token'] = token return redirect('axf:mine')
def register(request): if request.method == "GET": return render(request, 'mine/register.html') elif request.method == "POST": email=request.POST.get('email') password=request.POST.get('password') name=request.POST.get('name') token=generate_token() try: user=User() user.email=email user.password=generate_password(password) user.name=name user.token=token user.save() response=redirect('axf:mine') request.session['token']=user.token return response except: return render(request,'mine/register.html')
def login(request): if request.method == "GET": if request.is_ajax(): phoneNum = request.GET.get("phoneNum") # rand_str = random.randrange(1000, 10000) rand_str = "4125" # __business_id = uuid.uuid1() # params = "{\"code\":\"%s\"}" % rand_str # send_sms(__business_id, phoneNum, "捷豹快快", "SMS_135740070", params) request.session["code"] = rand_str return JsonResponse({"data": "ok"}) else: return render(request, 'mine/login.html') else: phoneNum = request.POST.get("username") passwd = request.POST.get("passwd") code = request.session.get("code") # print(code) # print(passwd) # print(type(code)) # print(type(passwd)) if passwd == code: # print("asdasd") uuidStr = uuid.uuid4() try: user = User.objects.get(phoneNum=phoneNum) user.tokenValue = uuidStr user.save() except User.DoesNotExist as e: user = User.create(phoneNum, None, uuidStr, "asdawdwd") user.save() request.session["phoneNum"] = phoneNum response = redirect("/mine/") # 将tokenValue写入cookie response.set_cookie("token", uuidStr) return response else: return redirect("/login/")
def register(request): if request.method == 'POST': userAccount = request.POST.get('userAccount') userPasswd = request.POST.get('userPasswd') userName = request.POST.get('userName') userPhone = request.POST.get('userPhone') userAdderss = request.POST.get('userAddress') userRank = 0 token = random.randrange(1, 100000) userToken = str(token) f = request.FILES['userImg'] userImg = os.path.join(settings.MEDIA_ROOT, userAccount + '.png') with open(userImg, 'wb') as fp: for data in f.chunks(): fp.write(data) user = User.createuser(userAccount, userPasswd, userName, userPhone, userAdderss, userRank, userToken, userImg) user.save() request.session['username'] = userName request.session['token'] = userToken return redirect('/mine/') else: return render(request, 'axf/register.html', {'title': '注册'})
def register(request): if request.method == 'GET': return render(request, 'register.html') elif request.method == 'POST': # 获取数据库 email = request.POST.get('email') name = request.POST.get('name') password = generate_password(request.POST.get('password')) # 存入数据库 user = User() user.email = email user.password = password user.name = name user.save() # 状态保持 token = generate_token() request.session['token'] = token cache.set(token, user.id) return redirect('axf:mine')
def registe(request): if request.method == 'GET': return render(request, 'mine/registe.html') elif request.method == 'POST': # try: user = User() user.account = request.POST.get('account') user.password = genarate_password(request.POST.get('password')) user.name = request.POST.get('name') user.phone = request.POST.get('phone') user.addr = request.POST.get('addr') # user.img = 'axf.png' # 头像 imgName = user.account + '.png' imagePath = os.path.join(settings.MEDIA_ROOT, imgName) file = request.FILES.get('icon') with open(imagePath, 'wb') as fp: for data in file.chunks(): fp.write(data) user.img = imgName user.token = str(uuid.uuid5(uuid.uuid4(), 'register')) user.save() # 状态保持 request.session['token'] = user.token # 重定向 return redirect('axf:mine')
def register(request): if request.method == 'POST': user = User() # 用户账号 user.account = request.POST.get('account') # 用户密码加密 user.password = generate_password(request.POST.get('password')) # 用户名 user.name = request.POST.get('name') # 电话 user.tel = request.POST.get('tel') # 地址 user.address = request.POST.get('address') # 头像 imgName = user.account + '.png' imgPath = os.path.join(settings.MEDIA_ROOT, imgName) print(imgPath) file = request.FILES.get('file') print(file) with open(imgPath, 'wb') as fp: for data in file.chunks(): fp.write(data) user.img = imgName # token user.token = str(uuid.uuid5(uuid.uuid4(), 'register')) # 用户保存 user.save() # 状态保持 request.session['token'] = user.token # 注册成功之后的重定向 return redirect('axf:mine') elif request.method == 'GET': return render(request,'mine/register.html')