当前位置: 首页>>代码示例>>Python>>正文


Python AuthenticationForm.clean方法代码示例

本文整理汇总了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,
    })
开发者ID:SanaMobile,项目名称:sana.protocol_builder,代码行数:33,代码来源:views.py

示例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
开发者ID:ckayorke,项目名称:finalmrv,代码行数:9,代码来源:forms.py

示例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)
开发者ID:kittuov,项目名称:quicktap-server,代码行数:30,代码来源:views.py

示例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
开发者ID:kevinhoa95,项目名称:specify7,代码行数:13,代码来源:views.py

示例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
开发者ID:incuna,项目名称:authentic,代码行数:12,代码来源:views.py

示例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
开发者ID:Zopieux,项目名称:django-cas-provider,代码行数:6,代码来源:forms.py


注:本文中的django.contrib.auth.forms.AuthenticationForm.clean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。