本文整理汇总了Python中app.forms.LoginForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.is_valid方法的具体用法?Python LoginForm.is_valid怎么用?Python LoginForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.is_valid方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_view
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def login_view(request):
elem = {
'title':'Login',
}
#inloggade användare behöver inte se login view
if request.user.is_authenticated():
return HttpResponseRedirect('/home/')
if request.method == 'POST':
loginform = LoginForm(request.POST)
loginAuth(request)
if loginform.is_valid():
if request.user.is_authenticated():
#endast för admin, som saknar user profile från början, underlättar testning
up = UserProfile.objects.filter(user=request.user)
if not up.exists():
new_profile = UserProfile(user=request.user, description=16*"admin")
new_profile.save()
return HttpResponseRedirect('/home/')
else:
return HttpResponseRedirect('')
loginform = LoginForm()
elem.update({'error':'inloggning misslyckades','login_form':loginform})
print "aha"
return render_to_response("login.html",elem,context_instance=RequestContext(request))
else:
loginform = LoginForm()
elem.update({'login_form':loginform})
return render_to_response("login.html",elem,context_instance=RequestContext(request))
示例2: post
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def post(self, request):
form = LoginForm(None, request.POST or None)
if form.is_valid():
login_user(request, form.get_user())
return redirect('index', permanent=True)
else:
return render(request, self.template_name, {'login_form': form})
示例3: login_view
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def login_view(request):
if request.user.is_authenticated():
if request.GET.get('next'):
return redirect(request.GET['next'])
else:
return redirect('dashboard')
if request.method == 'POST':
form = LoginForm(data=request.POST)
if form.is_valid():
user = form.login(request)
if user:
if user.is_active:
auth_login(request, user)
messages.success(request, 'Ingresaste con exito.')
if request.GET.get('next'):
return redirect(request.GET['next'])
else:
return redirect('dashboard')
else:
form = LoginForm()
return render(request, 'login.html', {
'form': form,
})
示例4: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def login(request,*kwargs):
form = LoginForm(request.POST if request.POST else None)
if form.is_valid():
login = RetailerLogin(request)
if( login.makeLogin(form) ):
return redirect('retailer-home-view')
else:
errors = form._errors.setdefault("systemerror", ErrorList())
errors.append(u'Dados de login Invalidos')
return render(request, 'retailer/login.html', {
'form': form,
},)
示例5: user_login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def user_login(request):
form = LoginForm(request = request)
if request.method == "POST":
form = LoginForm(request.POST, request = request)
if form.is_valid():
if request.session.has_key('next_view'):
if not (request.session['next_view'] == ""
or request.session['next_view'] == None):
next_view = request.session["next_view"]
del(request.session["next_view"])
return HttpResponseRedirect(next_view)
return render_to_response("login.html",
context_instance = RequestContext(request,
{"login_form" : form}))
示例6: login_user
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def login_user(request):
"""
Login request handler
"""
response = reply_object()
form = LoginForm(request.POST, request=request)
if form.is_valid():
response["code"] = settings.APP_CODE["LOGIN"]
response["next_view"] = reverse('home')
else:
response["code"] = settings.APP_CODE["FORM ERROR"]
response["errors"] = form.errors
return HttpResponse(simplejson.dumps(response))
示例7: login_view
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def login_view(request):
if request.user.is_authenticated():
return redirect(reverse('profile'))
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
user = authenticate(email=form.cleaned_data['email'], password=form.cleaned_data['password'])
if user:
login(request, user)
return redirect(reverse('index'))
else:
form = LoginForm()
return render(request, 'app/user/login.html', context={'form': form})
示例8: login_view
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def login_view(request):
bad_attempt = False
if request.method == "POST":
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data["login"]
password = form.cleaned_data["password"]
user = authenticate(username=username, password=password)
if user:
login(request, user)
return HttpResponseRedirect(reverse("rooms.views.list"))
else:
bad_attempt = True
else:
form = LoginForm()
return {"form": form, "bad_attempt": bad_attempt}
示例9: login_user
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def login_user(request):
response = reply_object()
form = LoginForm(request.POST, request = request)
if form.is_valid():
response["code"] = settings.APP_CODE["LOGIN"]
if request.session.has_key('next_view'):
if not (request.session['next_view'] == "" \
or request.session['next_view'] == None):
response["next_view"] = request.session["next_view"]
del(request.session["next_view"])
if not response.has_key("next_view"):
response["next_view"] = "/dashboard/"
else:
response["code"] = settings.APP_CODE["FORM ERROR"]
response["errors"] = form.errors
return HttpResponse(simplejson.dumps(response))
示例10: user_login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def user_login(request):
if request.user.is_authenticated():
return HttpResponseRedirect(reverse('private'))
else:
form_errors = None
if request.method == 'POST': # If the form has been submitted...
form = LoginForm(request.POST)
if form.is_valid():
user = form.authenticate_user()
if user:
login(request, user)
return HttpResponseRedirect(reverse('private'))
else:
return render(request, 'app/login.html', {'form': form, 'errors': _('Datos invalidos')})
else:
form_errors = form.errors
form = LoginForm(request.GET)
return render(request, 'app/login.html', {'form': form, 'errors': form_errors})
示例11: loginApp
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def loginApp(request):
"""
登陆操作,成功后更新时间
:param request:
:return:
"""
if request.method == 'POST':
login_form = LoginForm(request.POST)
if login_form.is_valid():
user = authenticate(username=login_form.cleaned_data['username'],
password=login_form.cleaned_data['password'])
if user and user.is_authenticated():
user.set_last_time() # 更新登录时间
login(request, user)
return redirect('/index') # Redirect after POST
else:
login_form = LoginForm()
return render(request, 'login.html', locals())
示例12: login_view
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def login_view(request):
mensaje = ""
if request.user.is_authenticated():
return HttpResponseRedirect('/')
else:
if request.method == "POST":
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
usuario = authenticate(username=username,password=password)
if usuario is not None and usuario.is_active:
login(request,usuario)
return HttpResponseRedirect("/")
else:
mensaje = "usuario y/o password incorrecto"
form = LoginForm()
ctx = {'form':form,'mensaje':mensaje}
return render_to_response('login.html',ctx,context_instance=RequestContext(request))
示例13: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import is_valid [as 别名]
def login(request):
locals().update(csrf(request))
ls = LockedStatus.objects.filter(name='login')
loginLocked = False
if ls and ls[0].is_lock:
loginLocked = True
if request.method == 'POST' and not loginLocked:
loginForm = LoginForm(request.POST)
if loginForm.is_valid():
people = People.objects.filter(
id_number=loginForm.cleaned_data['id_number'],
query_password=hashlib.md5(loginForm.cleaned_data['password']).hexdigest()
)
if people:
request.session['profile'] = people[0]
request.session.set_expiry(3600)
return redirect('/progress/')
else:
loginForm._errors[NON_FIELD_ERRORS] = loginForm.error_class([u'用户名或密码错误'])
else:
loginForm = LoginForm()
return render_to_response('login.html', locals())