def login(request): phonenum = request.POST.get('phonenum') vcode = int(request.POST.get('vcode')) if check_vcode(phonenum, vcode): user = User.objects.get_or_create(phonenum=phonenum) request.session['uid'] = user.id return render_json(user.to_dict()) else: return render_json(None, errors.VcodeError.code)
def login(request): '''注册、登录''' phonenum = request.POST.get('phonenum') vcode = request.POST.get('vcode') if check_vcode(phonenum, vcode): user, created = User.objects.get_or_create(phonenum=phonenum) request.session['uid'] = user.id return render_json(user.to_dict()) else: raise errors.VcodeError
def login(request): #获取前端数据 phone = request.POST.get('phone') vcode = request.POST.get('vcode') if check_vcode(phone,vcode): print('登录成功!@~') return JsonResponse({'msg':'ok'})
def login(request): phonenum = request.POST.get('phonenum') vcode = int(request.POST.get('vcode')) if not check_vcode(phonenum, vcode): user, created = User.get_or_create(phonenum=phonenum) request.session['uid'] = user.id pre_rcmd(user) return render_json(user.to_dict()) else: raise errors.VcodeError
def login(request): phonenum = request.POST.get("phonenum") vcode = request.POST.get("vcode") if check_vcode(phonenum, vcode): raise errors.VcodeError else: user, created = User.objects.get_or_create(phonenum=phonenum) request.session['uid'] = user.id # uid是动态改变的,而且是唯一的一个key只对应一个value,假设当一个用户登录时uid=1,下一用户登录时uid就是=其他了 pre_rcmd(user) return render_json(user.to_dict())
def login(request): # 获取前端提交的数据 phone = request.POST.get('phone') vcode = request.POST.get('vcode') # 检查用户的验证码是否正确 if check_vcode(phone, vcode): print("登录成功!") user, created = User.objects.get_or_create(nickname=phone, phonenum=phone) request.session['uid'] = user.id return render_json(user.to_dict()) else: print("验证码输入错误") return render_json("验证码错误", error.VCODE_ERROR)
def login(request): # 获取前端提交的数据 phone = request.POST.get('phone') vcode = request.POST.get('vcode') # 检查用户的验证码是否正确 if check_vcode(phone, vcode): print("登录成功!") # 自动注册账号:给User表添加一条记录 # User.objects.create(phonenum=phone) # 获取或者创建,如果没有该数据则创建并返回数据 user, created = User.objects.get_or_create(nickname=phone, phonenum=phone) # print(user, created) # 用session保存登录状态 request.session['uid'] = user.id return render_json(user.to_dict()) else: print("验证码输入错误") return render_json("验证码错误", errors.VCODE_ERROR)