def login(request): if request.method == 'GET': return render(request, 'booktest2/login.html') elif request.method == 'POST': # response = redirect(reverse('booktest2:indexes')) # response.set_cookie('name', request.POST.get('name')) # return response # request.session['name'] = request.POST.get('name') name = request.POST.get('name') password = request.POST.get('password') veritycode = request.POST.get('verity') # a = cache.get('verity') # print(veritycode) # print(a) if not veritycode == cache.get('verity'): return HttpResponse("验证码错误") user = authenticate(request, username=name, password=password) # print(user) # print(user.is_active) if user: if user.is_active: lgi(request, user) return render(reverse('booktest2:indexes')) else: return render(request, 'booktest2/login.html', {'errors': '尚未激活'}) else: return render(request, 'booktest2/login.html', {'errors': '登录失败'})
def login(request): # 获取表单类 lgf = LoginForm() rgf = RegistForm() if request.method == "GET": # 发送邮件验证 recvlist = ["*****@*****.**","*****@*****.**"] try: send_mail("邮箱发送验证","这是一封邮件",settings.EMAIL_HOST_USER,recvlist) print("send success") except Exception as e: print(e) return render(request,'myvote/login.html',{"lgf":lgf,"rgf":rgf}) elif request.method == "POST": # 验证码的判断 verifycode = request.POST.get("verify") if not verifycode == cache.get("verify"): return HttpResponse("验证码错误") lgf = LoginForm(request.POST) if lgf.is_valid(): username = lgf.cleaned_data["username"] password = lgf.cleaned_data["password"] user = authenticate(request,username = username,password=password) if user: lgi(request,user) return redirect(reverse("myvote:index")) else: return render(request, 'myvote/login.html', {"errors": "登录失败","lgf":lgf,"rgf":rgf}) else: return render(request, 'myvote/login.html', {"errors": "登录失败","lgf":lgf,"rgf":rgf})
def login(request): if request.method == 'GET': return render(request, 'poils/login.html') else: username = request.POST.get('username') pwd = request.POST.get('password') # 第一种,不用激活直接进入 # user = authenticate(request, username=username, password=pwd) # if user: # lgi(request, user) # return redirect(reverse('poils:index')) # else: # return render(request, 'poils/login.html') verifycode = request.POST["verify"] # 判断验证码是否输入正确 if verifycode == request.session["verifycode"]: # 第二种: 判断用户是否激活 user = get_object_or_404(MyUser, username=username) if not user.is_active: error = '用户尚未激活' return render(request, 'poils/login.html', locals()) else: check = user.check_password(pwd) if check: lgi(request, user) return redirect(reverse('poils:index')) else: return render(request, 'poils/login.html', {'error': '用户名或者密码错误'}) else: return render(request, 'poils/login.html', {"error": "验证码错误"})
def login(request): if request.method == "GET": # lf = LoginForm() # rf = RegisterForm() # return render(request, 'polls/login.html',{"lf":lf, "rf":rf}) return render(request, 'polls/login.html') else: # 没有使用Django自带用户系统 # username = request.POST.get("username") # if username == "zzy": # # 登录成功之后需要将用户相关cookie存储 # res = redirect(reverse('polls:index')) # # 设置cookit完成登录 # # res.set_cookie("username", username) # # 通过session完成登录 # request.session["username"] = username # return res # else: # return render(request, 'polls/login.html', {"error": "用户名错误"}) # 使用django授权系统 username = request.POST.get("username") pwd = request.POST.get("password") # MyUser.objects.filter(username = username, p) user = authenticate(request, username = username,password = pwd) if user: print(user) lgi(request,user) return redirect(reverse('polls:index')) else: return render(request, 'polls/login.html', {"error": "用户名或者密码错误"})
def login(request): """登录""" if request.method == 'GET': return render(request, 'login.html') elif request.method == 'POST': username = request.POST.get('username') pwd = request.POST.get('password') verifycode = request.POST["verify"] print('*********', username, pwd, verifycode) print("@@@@@@@@@@@@@@") # user = get_object_or_404(MyUser, username=username) # # check = user.check_password(pwd) # 使用中间件,系统自带登录判断 user = authenticate(request, username=username, password=pwd) # print('##########', user, check) print(user) # 判断账号输入正确 if user: # 判断验证码是否输入正确 if verifycode == request.session["verifycode"]: lgi(request, user) return redirect(reverse('babymall:index')) else: messages.error(request, "验证码错误,请重新输入") return render(request, 'login.html') else: messages.error(request, "账号或密码错误,请重新登录") return render(request, 'login.html')
def login(request): """登录""" if request.method == 'GET': return render(request, 'poll/login.html') elif request.method == 'POST': # 1.使用cookie存储信息 # response = redirect(reverse('poll:index')) # response.set_cookie('username', request.POST.get('username')) # return response # 2.使用session存储信息 # request.session['username'] = request.POST.get('username') # return redirect(reverse('poll:index')) username = request.POST.get('username') password = request.POST.get('password') verifycode = request.POST.get('verify') if not verifycode == cache.get('verify').lower(): return HttpResponse('验证码错误') user = authenticate(request, username=username, password=password) if user: lgi(request, user) return redirect(reverse('poll:index')) else: return redirect(reverse('poll:login'))
def post(self, request, *args, **kwargs): user = self.valid_user(request) if user is not None: lgi(request, user) rember = request.POST.get('rember') if not rember: request.session.set_expiry(0) return redirect('web:index') self.get(request, *args, **kwargs)
def login(request): if request.method == "GET": form = LoginForm() return render(request, 'vote/login.html', {'form': form}) elif request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') user = authenticate(request, username=username, password=password) if user: lgi(request, user) return redirect(reverse("vote:index")) else: return render(request, 'vote/login.html', {"errors": "登陆失败"})
def login(request): # 自己的第一种方法 # if request.method == 'GET': # return render(request,'votetest/login.html') # else: # username = request.POST.get("username") # userpwd = request.POST.get('userpwd') # try: # user = User.objects.get(name=username,pwd=userpwd) # res = redirect(reverse('votetest:index')) # request.session['username'] = user.name # return res # except: # return render(request,'votetest/login.html',{'error':'用户名错误'}) # # 第二种方法,使用Django自带用户系统 if request.method == "GET": return render(request, 'votetest/login.html') else: username = request.POST.get('username') pwd = request.POST.get('userpwd') verifycode = request.POST.get('verify') # 如果在session中的验证码相等 if verifycode == request.session.get('verifycode'): # user = authenticate(request,username = username,password = pwd) user = get_object_or_404(MyUser, username=username) # 核对用户输入密码和数据库密码(数据库密码加密,只能用用这种方式对比) print(user.is_active) if not user.is_active: return render(request, 'votetest/login.html', {'error': '用户尚未激活'}) else: check = user.check_password(pwd) if check: lgi(request, user) return redirect(reverse('votetest:index')) else: return render(request, 'votetest/login.html', {'error': '用户名或者密码错误'}) else: return render(request, 'votetest/login.html', {'error': '验证码错误'})
def login(request): if request.method == 'POST': username = request.POST['username'] password = request.POST['password'] rember = request.POST.get('rember') user = authenticate(request, username=username, password=password) if user is not None: lgi(request, user) if not rember: request.session.set_expiry(0) return redirect('web:index') return render(request, 'login.html')
def login(request): if request.method == 'POST': username = request.POST.get('username') pwd = request.POST.get('password') user = authenticate(request, username=username, password=pwd) if user: lgi(request, user) return redirect(reverse('animal:index')) else: return render( request, 'index.html', )
def login(request): lgf = LoginForm() if request.method == "GET": return render(request, "shop/login.html", {"lgf": lgf}) else: verifycode = request.POST.get("verify") print(verifycode) if not verifycode.lower() == cache.get("verify").lower(): return render(request, 'shop/login.html', { "errors": "验证码错误", "lgf": lgf }) # lgf = LoginForm(request.POST) # print(lgf) # if lgf.is_valid(): username = request.POST.get("username") password = request.POST.get("password") print(password) user = PollsUser.objects.filter(username=username).first() if user.check_password(password): print(user) if user: if user.is_active: lgi(request, user) return redirect(reverse("shop:index")) else: return render(request, 'shop/login.html', { "errors": "账户尚未激活", "lgf": lgf }) else: print("----") return render(request, 'shop/login.html', { "errors": "登录失败", "lgf": lgf }) else: return render(request, 'shop/login.html', { "errors": "密码错误", "lgf": lgf })
def login(request): if request.method == 'GET': return render(request, 'polls/login.html') else: username = request.POST.get('username') pwd = request.POST.get('password') user = get_object_or_404(MyUser, username=username) print('active:', user.is_active) if not user.is_active: return render(request, 'polls/login.html', {'error': '用户尚未激活'}) else: check = user.check_password(pwd) if check: lgi(request, user) return redirect(reverse('polls:index')) else: return render(request, 'polls/login.html', {'error': '用户名或密码错误'})
def login(request): if request.method == 'GET': return render(request, 'booktest/login.html') # elif request.method == 'POST': # username = request.POST['username'] # request.session['username'] = username # return redirect(reverse('booktest:index')) else: username = request.POST.get('username') pwd = request.POST.get('password') user = authenticate(request, username=username, password=pwd) if user: # request.session['username'] = username lgi(request, user) return redirect(reverse('booktest:index')) else: return render(request, 'booktest/login.html', {"error": "用户名或者密码错误"})
def login(request): if request.method == 'GET': from .forms import loginForm lf = loginForm() return render(request, 'vote/login.html', {'lf': lf}) else: # username=request.POST.get('name') # print(username) # pwd=request.POST.get('pwd') # # print(VoteUser.objects.all().filter(name=username).filter(pwd=pwd)) # if username != None : # res=redirect(reverse('vote:index')) # request.session['username']=username # request.session['pwd'] = pwd # return res # else: # return render(request,'vote/login.html',{'error':'用户错误'}) username = request.POST.get('username') pwd = request.POST.get('pwd') verifycode = request.POST.get('verify') if verifycode == request.session.get('verifycode'): # user=authenticate(request,username=username,password=pwd) user = get_object_or_404(MyUser, username=username) if not user.is_active: return render(request, 'vote/login.html', {"error": "用户名尚未激活"}) else: check = user.check_password(pwd) if check: lgi(request, user) return redirect(reverse('vote:index')) else: return render(request, 'vote/login.html', {'error': '用户或者密码错误'}) # print(user) # if user: # lgi(request,user) # return redirect(reverse('vote:index')) # else: # return render(request,'vote/login.html',{"error": "用户名或者密码错误"}) else: return render(request, 'vote/login.html', {'error': '验证码错误'})
def login(request): lgf = LoginForm() rgf = RegistForm() if request.method == "GET": # 发送邮件 SMTP POP3 IMAP return render(request,'polls/login.html',{"lgf":lgf,"rgf":rgf}) elif request.method == "POST": # username = request.POST.get("username") # password = request.POST.get("password") verifycode = request.POST.get("verify") if not verifycode == cache.get("verify"): return HttpResponse("验证码错误") lgf = LoginForm(request.POST) if lgf.is_valid(): username = lgf.cleaned_data["username"] password = lgf.cleaned_data["password"] # user = authenticate(request,username = username,password=password) user = PollsUser.objects.filter(username=username).first() if user.check_password(password): print(user) if user: if user.is_active: lgi(request,user) return redirect(reverse("polls:index")) else: return render(request, 'polls/login.html', {"errors": "账户尚未激活", "lgf": lgf, "rgf": rgf}) else: print("----") return render(request, 'polls/login.html', {"errors": "登录失败","lgf":lgf,"rgf":rgf}) else: return render(request, 'polls/login.html', {"errors": "密码错误", "lgf": lgf, "rgf": rgf}) else: print("++++") return render(request, 'polls/login.html', {"errors": "登录失败","lgf":lgf,"rgf":rgf})
def login(request): if request.method == 'GET': lf = LoginForm() rf = RegisterForm() return render(request, 'vote/login.html', {'lf': lf, 'rf': rf}) else: lf = LoginForm(request.POST) if lf.is_valid(): print() username = lf.cleaned_data["username"] pwd = lf.cleaned_data["password"] user = authenticate(request, username=username, password=pwd) if user: lgi(request, user) return redirect(reverse('vote:index')) else: return render(request, 'vote/login.html', {'error': "用户名或密码错误"})
def login(request): if request.method == "GET": # lf = LoginForm() # rf = RegisterForm() # return render(request, 'polls/login.html',{"lf":lf, "rf":rf}) return render(request, 'polls/login.html') else: # 没有使用Django自带用户系统 # username = request.POST.get("username") # if username == "zzy": # # 登录成功之后需要将用户相关cookie存储 # res = redirect(reverse('polls:index')) # # 设置cookit完成登录 # # res.set_cookie("username", username) # # 通过session完成登录 # request.session["username"] = username # return res # else: # return render(request, 'polls/login.html', {"error": "用户名错误"}) # 使用django授权系统 username = request.POST.get("username") pwd = request.POST.get("password") verifycode = request.POST.get("verify") if verifycode == cache.get("verifycode"): # if verifycode == request.session.get("verifycode"): # MyUser.objects.filter(username = username, p) # user = authenticate(request, username = username,password = pwd) user = get_object_or_404(MyUser, username=username) if not user.is_active: return render(request, 'polls/login.html', {"error": "用户尚未激活"}) else: check = user.check_password(pwd) if check: lgi(request, user) return redirect(reverse('polls:index')) else: return render(request, 'polls/login.html', {"error": "用户名或者密码错误"}) # print(user) # if user: # print(user) # if user.is_active: # lgi(request,user) # return redirect(reverse('polls:index')) # else: # return render(request, 'polls/login.html', {"error": "用户尚未激活"}) # else: # return render(request, 'polls/login.html', {"error": "用户名或者密码错误"}) # 使用自动生成表单post # lf = LoginForm(request.POST) # if lf.is_valid(): # username = lf.cleaned_data["username"] # pwd = lf.cleaned_data["password"] # # MyUser.objects.filter(username = username, p) # user = authenticate(request, username = username,password = pwd) # if user: # print(user) # lgi(request,user) # return redirect(reverse('polls:index')) # else: # return render(request, 'polls/login.html', {"error": "用户名或者密码错误"}) else: return render(request, 'polls/login.html', {"error": "验证码错误"})
def login(request): lgf = LoginForm() rgf = RegistForm() if request.method == "GET": return render(request, 'polls/login.html', {"lgf": lgf, "rgf": rgf}) elif request.method == "POST": # username = request.POST.get("username") # password = request.POST.get("password") verifycode = request.POST.get("verify") if not verifycode.lower() == cache.get("verify").lower(): return render(request, 'polls/login.html', { "errors": "验证码错误", "lgf": lgf, "rgf": rgf }) lgf = LoginForm(request.POST) # print(lgf.is_valid()) if lgf.is_valid(): username = lgf.cleaned_data["username"] password = lgf.cleaned_data["password"] # print("***************") # print(username) # print(password) # user = authenticate(request,username=username,password=password) # user = PollsUser.objects.filter(username=username).first() # user = PollsUser.objects.filter(username=username).first() # if user.check_passwork(password): # if user: # if user.is_active: # lgi(request,user) # return redirect(reverse("polls:index")) # else: # return render(request, 'polls/login.html', {"errors": "登录失败,用户未激活", "lgf": lgf, "rgf": rgf}) # else: # return render(request, 'polls/login.html', {"errors": "登录失败,账号或密码错误","lgf":lgf,"rgf":rgf}) # else: # return render(request, 'polls/login.html', {"errors": "登录失败,密码错误", "lgf": lgf, "rgf": rgf}) # else: # return render(request, 'polls/login.html', {"errors": "登录失败","lgf":lgf,"rgf":rgf}) user = PollsUser.objects.filter(username=username).first() if user.check_password(password): print(user) if user: if user.is_active: lgi(request, user) return redirect(reverse("polls:index")) else: return render(request, 'polls/login.html', { "errors": "账户尚未激活", "lgf": lgf, "rgf": rgf }) else: print("----") return render(request, 'polls/login.html', { "errors": "登录失败", "lgf": lgf, "rgf": rgf }) else: return render(request, 'polls/login.html', { "errors": "密码错误", "lgf": lgf, "rgf": rgf }) else: print("++++") return render(request, 'polls/login.html', { "errors": "登录失败", "lgf": lgf, "rgf": rgf })