本文整理汇总了Python中form.LoginForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.is_valid方法的具体用法?Python LoginForm.is_valid怎么用?Python LoginForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类form.LoginForm
的用法示例。
在下文中一共展示了LoginForm.is_valid方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: usLogin
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import is_valid [as 别名]
def usLogin(request):
context = {}
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
us = form.cleaned_data['us']
pwd = form.cleaned_data['pwd']
if r.exists('us:%s:id' %us): # 检查是否存在该用户关系键值
uid = r.get('us:%s:id' %us) # 获取该用户在user表中对应的id
if r.exists('user:%s' %uid): # 检查是否存在该用户键值(如user:1)
us_, pwd_ = r.hmget('user:%s' %uid, 'username', 'pwd') # 获取该用户的用户名密码
if us_ == us and pwd_ == pwd: # 校验成功
r.hincrby('user:%s' %uid, 'login_count', 1) # 登陆次数累加
r.hset('user:%s' %uid, 'last_login_date', datetime.datetime.now()) # 添加最近登陆
# set Cookies
res = HttpResponseRedirect('/')
ussys = usSystem(request, res, uid)
if ussys.testCookie() and ussys.setCookieAndSession():
return res
context['msg'] = u'账号或密码错误'
context['form'] = form
request.session.set_test_cookie()
form = LoginForm()
context['form'] = form
return render(request, 'login.html', context)
示例2: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import is_valid [as 别名]
def login(request):
param={}
if request.method=="POST":
form = LoginForm(request.POST)
if not form.is_valid():
return HttpResponseRedirect('/login/')
else:
return HttpResponseRedirect('/sample/')
else:
form = LoginForm()
param['form']=form
param.update(csrf(request))
return render_to_response('login.html',param)
示例3: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import is_valid [as 别名]
def login(request):
"""登陆只接受POST,无法正常访问"""
if request.method == "POST":
form = LoginForm(request.POST)
if form.is_valid():
data = form.cleaned_data
u_email = data['email']
u_psd = data['password']
# return render(request, 'index.html',{'login_error':request.META.get('HTTP_REFERER', '/')})
try:
user = User.objects.get(email=u_email)
# 登录错误检查
login_error = user.login_error
last_time = user.last_time
now = datetime.datetime.utcnow().replace(tzinfo=utc)
del_s = now - last_time
wait_time = (login_error - 3) * 5
if del_s.seconds > wait_time * 60:
# 如果相差的时间大于必须等待的秒数,可以正常登录一次
pass
else:
if login_error > 3:
return HttpResponse('由于错误次数过多,已经帮您锁住.请%s分钟之后再试'% wait_time)
if user.psd != hashlib.sha1(u_psd).hexdigest():
# 如果密码不正确查询错误次数
user.login_error += 1
user.save()
# remainder = 4 - login_error
return HttpResponse('邮箱或密码错误')
else:
# 检查是否验证了邮箱
if not user.is_veri:
return HttpResponse("可以麻烦您验证一下邮箱么⊙︿⊙")
else:
# 登录成功
name = user.name
request.session['name'] = name + "&" + str(user.id) # 总觉得空格不太好
# print name
user.last_time = 0
user.save()
return JsonResponse({'status': 'ok'})
except User.DoesNotExist:
return HttpResponse('邮箱或密码错误')
else:
return HttpResponse('邮箱或密码错误')
示例4: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import is_valid [as 别名]
def login(request):
error=[]
if request.method=='POST':
form=LoginForm(request.POST)
if form.is_valid():
data=form.cleaned_data
username=data['username']
password=data['password']
if login_validate(request,username,password):
# return render_to_response('index.html',{'user':username})
return render_to_response('index.html',{'user':username},context_instance=RequestContext(request));
else:
error.append('please in put eorrect password')
else:
error.append('Please input both username and password')
else:
form=LoginForm()
return render_to_response('login.html',{'error':error,'form':form})
示例5: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import is_valid [as 别名]
def login(request):
"""登陆只接受POST,无法正常访问"""
if request.method == "POST":
form = LoginForm(request.POST)
if form.is_valid():
data = form.cleaned_data
u_email = data["email"]
u_psd = data["password"]
user = User.objects.filter(email=u_email, psd=hashlib.sha1(hashlib.sha1(u_psd).hexdigest()).hexdigest())
if user:
# response = HttpResponseRedirect('/')
response = HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
name = user[0].name
request.session["name"] = name + " " + str(user[0].id)
return response
else:
# return HttpResponseRedirect("/"+"?error=loginerror&a=%s"%hashlib.sha1(u_psd).hexdigest())
return HttpResponseRedirect("/" + "?error=loginerror")
示例6: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import is_valid [as 别名]
def login(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user = auth.authenticate(username=username, password=password)
if user is not None and user.is_active:
auth.login(request, user)
return HttpResponseRedirect(reverse('index'))
else:
form._errors.setdefault("username", ErrorList())\
.append(u"Неверный логин или пароль.")
else:
form = LoginForm()
return render(request, 'account/login.html', {
'form': form,
})
示例7: auth_login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import is_valid [as 别名]
def auth_login(request):
form = LoginForm(request.POST or None)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user = authenticate(username=username,password=password)
if user:
login(request,user)
messages.success(request,'You successfully logged in!')
else:
messages.error(request,'Please try again.')
return HttpResponseRedirect(reverse('auth_login'))
return HttpResponseRedirect(reverse('home'))
context = {'login_form' : LoginForm}
template = 'auth/authentication.html'
return render(request,template,context)
示例8: login_user
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import is_valid [as 别名]
def login_user(request):
data = {}
form = LoginForm(request.POST)
data["form"] = form
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
# call login
login(request, user)
return HttpResponseRedirect('/blog/home')
else:
data["invalid_login"] = "Account Disabled, contact administrator"
else:
# invalid login
data["invalid_login"] = "Bad credential, username and password don't match"
return render_to_response(USER_TEMPLATE + 'login.html', data, context_instance=RequestContext(request))
示例9: auth_login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import is_valid [as 别名]
def auth_login(request):
login_form = LoginForm(request.POST or None)
if login_form.is_valid():
username = login_form.cleaned_data['username']
# email_address = login_form.cleaned_data['email']
password = login_form.cleaned_data['password']
try:
user = User.objects.get(username=username)
user_auth = authenticate(username=user.username,password=password)
except:
user_auth = None
if user_auth:
login(request,user_auth)
messages.success(request,'You successfully logged in!')
else:
messages.error(request, "Incorrect: Username and Password!")
return HttpResponseRedirect(reverse('auth_login'))
return HttpResponseRedirect(reverse('home'))
context = {'login_form' : login_form}
template = 'account/login.html'
return render(request,template,context)