def post(self, request): # 获取数据 data = request.POST # 验证数据合法性 login_form = LoginModelForm(data) if login_form.is_valid(): # 操作数据库 # 保存登录标识到session中, 单独创建一个方法保存, 更新个人资料 user = login_form.cleaned_data['user'] request.session['ID'] = user.pk request.session['tel'] = user.tel # request.session['head'] = user.head request.session.set_expiry(0) #关闭浏览器就消失 # login(request, user) referer = request.session.get('referer') if referer: # 跳转回去 # 删除session del request.session['referer'] return redirect(referer) else: # 合成响应, 跳转到个人中心 return redirect('user:个人中心') else: return render(request, 'user/login.html', {'form': login_form})
def post(self, request): # 接收参数 data = request.POST # 验证数据的合法性 login_form = LoginModelForm(data) if login_form.is_valid(): # 验证成功 # 数据合法 # 从session中得到数据 # 单独创建方法保存session,更新资料 user = login_form.cleaned_data.get('user') # request.session['ID'] = user.pk # request.session['username'] = user.username login(request, user) referer = request.session.get('referer') if referer: # 跳转回去 # 删除session del request.session['referer'] return redirect(referer) return redirect('用户:个人中心') else: # 合成响应 # 进入到登录页面 return render(request, 'user/login.html', {'form': login_form})
def post(self, request): # 接收参数 data = request.POST # 表单验证合法 form = LoginModelForm(data) if form.is_valid(): user = form.cleaned_data.get('user') request.session['ID'] = user.pk request.session['phone'] = user.phone return redirect('com:首页') else: return render(request, 'user/login.html', context={'form': form})
def post(self, request): # 接受参数 data = request.POST # 验证表单合法 form = LoginModelForm(data) if form.is_valid(): user = form.cleaned_data['user'] login(request, user) return redirect('user:个人中心') else: return render(request, 'user/login.html', context={'form': form})
def post(self, request): form = LoginModelForm(request.POST) if form.is_valid(): # 验证成功,保存登录标识到session中 user = form.cleaned_data.get('user') request.session['ID'] = user.pk request.session['tel'] = user.tel request.session.set_expiry(0) # 跳转到个人中心 # 如果有参数,跳转到指定界面 if request.GET.get('next', None): return redirect(request.GET.get('next')) return redirect(reverse('user:center')) # 验证失败 return render(request, 'user/login.html', {'form': form})
def post(self, request): #获取数据 data = request.POST #验证合法性 #操作数据库 login_form = LoginModelForm(data) if login_form.is_valid(): user = login_form.cleaned_data['user'] login(request, user) #合成响应 # return redirect('user:个人中心') return HttpResponse("ko") else: return render(request, 'user/login.html', {'form': login_form})
def post(self, request): data = request.POST form = LoginModelForm(data) if form.is_valid(): user = form.cleaned_data.get('user') # 设置session set_session(request, user) # 获取referer referer = request.session.get('referer') # 判断是否存在 if referer: # 存在就跳转回原URL return redirect(referer) else: # 不出在就跳转登录中心 return redirect('user:个人中心') else: context = {'data': data, 'form': form} return render(request, 'user/login.html', context=context)
def post(self, request): # 接收参数 data = request.POST form = LoginModelForm(data) if form.is_valid(): # 根据参数进行判断,通过跳转商品列表 user = form.cleaned_data.get('user') login(request, user) referer = request.session.get('referer') if referer: # 跳转回去 # 删除session del request.session['referer'] return redirect(referer) else: # 合成响应, 跳转到个人中心 return redirect('user:个人中心') else: # 判断不通过,报错 return render(request, 'user/login.html', {'form': form})
def post(self, request): # 获取数据 data = request.POST # 验证数据合法性 login_form = LoginModelForm(data) if login_form.is_valid(): # 操作数据库 # 保存登录标识到session中 user = login_form.cleaned_data['user'] login(request, user) referer = request.session.get('referer') if referer: # 跳转回去 del request.session['referer'] return redirect(referer) else: # 合成响应, 跳转到个人中心 return redirect('user:个人中心') else: context = {'errors': login_form.errors} return render(request, 'user/login.html', context=context)
def post(self, request): # 接收参数 data = request.POST # 验证数据的合法性 login_form = LoginModelForm(data) if login_form.is_valid(): # 操作数据库 # 保存登录标识到session中,单独创建一个方法保存,更新个人资料 user = login_form.cleaned_data["user"] set_session(request, user) referer = request.session.get('referer') if referer: # 跳转回去 return redirect(referer) else: # 合成响应 跳转到个人中心 return redirect('user:个人中心') else: return render(request, 'user/login.html', {'form': login_form})
def post(self, request): #获取数据 data = request.POST #表单验证 form = LoginModelForm(data) if form.is_valid(): #操作数据库 #登陆信息保存在session中 user = form.cleaned_data.get("user") request.session['id'] = user.pk request.session['user_phone'] = user.user_phone # request.session.set_expiry(0) referer = request.session.get('referer') #跳转到个人中心 if referer: del request.session['referer'] return redirect(referer) else: return redirect(reverse("user:member")) else: # 数据不合法 return render(request, 'user/login.html', context={"form": form})
def post(self, request): # 接收参数 data = request.POST # 验证数据的合法性 login_form = LoginModelForm(data) if login_form.is_valid(): # 验证成功 # 数据合法 password = login_form.cleaned_data['password'] username = login_form.cleaned_data.get('username') password = set_password(password) # 更新用户密码 Users.objects.filter(username=username).update(password=password) # 操作数据库 # 返回到登录 return redirect('用户:忘记密码') else: # 合成响应 # 验证不通过,返回注册页面 # 进入到注册页面 return render(request, 'user/forgetpassword.html', {'form': login_form})
def post(self, request): data = request.POST # 数据进行合法性验证 form = LoginModelForm(data) if form.is_valid(): # 如果数据合法 user = form.cleaned_data.get('user') # 设置session # request.session['ID'] = user.pk # request.session['user_name'] = user.user_name # request.session['head'] = user.head # request.session.set_expiry(9999) # 9999秒后就消失 login(request, user) referer = request.session.get('referer') if referer: del request.session['referer'] return redirect(referer) else: return redirect('user:member') else: # 数据不合法 回显网页 context = {'data': form.errors} return render(request, 'user/login.html', context=context)
def post(self, request): # 接收参数 data = request.POST # 验证数据的合法性 form = LoginModelForm(data) if form.is_valid(): # 验证成功 # 保存登录标识到session中,单独创建一个方法保存,更新个人资料 user = form.cleaned_data.get('user') login(request, user) # 保存session referer = request.session.get('referer') if referer: # 跳转回去 # 删除session del request.session['referer'] return redirect(referer) else: # 合成响应跳转到个体中心 return redirect('user:个人中心') else: # 提示错误,重新登录 return render(request, 'user/login.html', {'form': form})