本文整理汇总了Python中django.contrib.auth.forms.AuthenticationForm.clean方法的典型用法代码示例。如果您正苦于以下问题:Python AuthenticationForm.clean方法的具体用法?Python AuthenticationForm.clean怎么用?Python AuthenticationForm.clean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.forms.AuthenticationForm
的用法示例。
在下文中一共展示了AuthenticationForm.clean方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import clean [as 别名]
def login(request):
form = AuthenticationForm(data=request.POST)
valid_form = form.is_valid()
token_key = None
user_details = {}
if valid_form:
form.clean() # Calls authenticate(); will through ValidationException if form is invalid
user = form.get_user()
token, created = Token.objects.get_or_create(user=user)
utc_now = timezone.now()
if not created and token.created < utc_now - timedelta(hours=24):
token.delete()
token = Token.objects.create(user=user)
token.created = utc_now
token.save()
token_key = token.key
logger.info("Login Success: u:{0} e:{0}".format(user.username, user.email))
user_details = _getUserDetails(user)
else:
logger.info("Login Failed: {0}".format(_flattenFormErrors(form)))
return JsonResponse({
'success': valid_form,
'errors': form.errors,
'token': token_key,
'user': user_details,
})
示例2: clean
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import clean [as 别名]
def clean(self):
AuthenticationForm.clean(self)
try:
self.cleaned_data.get('lt').delete()
except:
pass
return self.cleaned_data
示例3: login
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import clean [as 别名]
def login(request):
if request.method == "GET":
if request.session.get("profile-id") is not None:
try:
profile = Profile.objects.get(pk=request.session.get("profile-id"))
serializer = ProfileSerializer(profile)
content = JSONRenderer().render(serializer.data)
return HttpResponse(content=content, status=200)
except Profile.DoesNotExist:
return logout(request)
content = JSONRenderer().render(
[{"name": "username", "type": "text", "label": "Username"},
{"name": "password", "type": "password", "label": "Password"}])
return HttpResponse(content=content, status=401)
if request.method == "POST":
form = AuthenticationForm(request, data=request.POST)
form.clean()
if not form.is_valid():
content = JSONRenderer().render(form.errors)
return HttpResponse(content=content, status=401)
user = form.get_user()
auth_login(request, user)
profile = Profile.objects.get(user=user)
profile.login(request)
serializer = ProfileSerializer(profile)
content = JSONRenderer().render(data=serializer.data)
return HttpResponse(content=content, status=200)
示例4: clean
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import clean [as 别名]
def clean(self):
AuthenticationForm.clean(self)
collection = self.cleaned_data.get('collection')
if self.user_cache is not None:
try:
Agent.objects.get(division=collection.discipline.division,
specifyuser=self.user_cache)
except Agent.DoesNotExist:
raise forms.ValidationError("The user has no agent for the chosen collection.")
collection_cell.append(collection.id)
return self.cleaned_data
示例5: clean
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import clean [as 别名]
def clean(self):
res = AuthenticationForm.clean(self)
# create an authentication event
if self.user_cache and NONCE_FIELD_NAME in self.cleaned_data:
how = 'password'
if self.request and 'HTTPS' in self.request.environ:
how = 'password-on-https'
models.AuthenticationEvent(who=self.user_cache.username,
how=how, nonce=self.cleaned_data[NONCE_FIELD_NAME]).save()
return res
示例6: clean
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import clean [as 别名]
def clean(self):
AuthenticationForm.clean(self)
self.cleaned_data.get('lt').delete()
return self.cleaned_data