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


Python default_token_generator.check_token方法代码示例

本文整理汇总了Python中django.contrib.auth.tokens.default_token_generator.check_token方法的典型用法代码示例。如果您正苦于以下问题:Python default_token_generator.check_token方法的具体用法?Python default_token_generator.check_token怎么用?Python default_token_generator.check_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.auth.tokens.default_token_generator的用法示例。


在下文中一共展示了default_token_generator.check_token方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clean

# 需要导入模块: from django.contrib.auth.tokens import default_token_generator [as 别名]
# 或者: from django.contrib.auth.tokens.default_token_generator import check_token [as 别名]
def clean(self):
        cleaned_data = super().clean()

        token = cleaned_data["token"]
        userid = urlsafe_b64decode(cleaned_data["encoded_user_id"])

        user = User.objects.filter(id=userid).first()

        if not user:
            raise ValidationError({"encoded_user_id": _("Invalid user")})

        if not default_token_generator.check_token(user, token):
            raise ValidationError({"token": _("Invalid token")})

        cleaned_data["user"] = user
        return cleaned_data 
开发者ID:pythonitalia,项目名称:pycon,代码行数:18,代码来源:forms.py

示例2: validate

# 需要导入模块: from django.contrib.auth.tokens import default_token_generator [as 别名]
# 或者: from django.contrib.auth.tokens.default_token_generator import check_token [as 别名]
def validate(self, attrs):
        self._errors = {}

        # Decode the uidb64 to uid to get User object
        try:
            uid = force_text(uid_decoder(attrs['uid']))
            self.user = UserModel._default_manager.get(pk=uid)
        except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
            raise ValidationError({'uid': ['Invalid value']})

        self.custom_validation(attrs)
        # Construct SetPasswordForm instance
        self.set_password_form = self.set_password_form_class(
            user=self.user, data=attrs
        )
        if not self.set_password_form.is_valid():
            raise serializers.ValidationError(self.set_password_form.errors)
        if not default_token_generator.check_token(self.user, attrs['token']):
            raise ValidationError({'token': ['Invalid value']})

        return attrs 
开发者ID:Tivix,项目名称:django-rest-auth,代码行数:23,代码来源:serializers.py

示例3: initial

# 需要导入模块: from django.contrib.auth.tokens import default_token_generator [as 别名]
# 或者: from django.contrib.auth.tokens.default_token_generator import check_token [as 别名]
def initial(self, request, *args, **kwargs):
        uidb64 = kwargs['uidb64']
        uid = urlsafe_base64_decode(force_text(uidb64))

        try:
            self.user = User.objects.get(pk=uid)
        except User.DoesNotExist:
            raise exceptions.InvalidExpiredToken()

        token = kwargs['token']
        if not default_token_generator.check_token(self.user, token):
            raise exceptions.InvalidExpiredToken()

        return super(OneTimeUseAPIMixin, self).initial(
            request,
            *args,
            **kwargs
        ) 
开发者ID:incuna,项目名称:django-user-management,代码行数:20,代码来源:views.py

示例4: validate

# 需要导入模块: from django.contrib.auth.tokens import default_token_generator [as 别名]
# 或者: from django.contrib.auth.tokens.default_token_generator import check_token [as 别名]
def validate(self, attrs):
        user = get_user_from_uid(attrs.get('uid'))
        value = attrs['token']

        if not default_token_generator.check_token(user, value):
            raise ValidationError(_("Invalid token: %s") % value)

        return attrs 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:10,代码来源:password_reset_serializer.py

示例5: post

# 需要导入模块: from django.contrib.auth.tokens import default_token_generator [as 别名]
# 或者: from django.contrib.auth.tokens.default_token_generator import check_token [as 别名]
def post(self, request, uidb64=None, token=None, *args, **kwargs):
        userModel = get_user_model()
        form = self.form_class(request.POST)

        if uidb64 is None or token is None:
            form.add_error(
                field=None, error=u"O link usado para a troca de senha não é válido ou expirou, por favor tente enviar novamente.")
            return self.form_invalid(form)

        try:
            uid = urlsafe_base64_decode(uidb64)
            user = userModel._default_manager.get(pk=uid)
        except (TypeError, ValueError, OverflowError, userModel.DoesNotExist):
            user = None

        if user is not None and default_token_generator.check_token(user, token):
            if form.is_valid():
                new_password = form.cleaned_data['new_password']
                new_password_confirm = form.cleaned_data[
                    'new_password_confirm']
                if new_password == new_password_confirm:
                    user.set_password(new_password)
                    user.save()
                    messages.success(request, u"Senha trocada com sucesso")
                    return self.form_valid(form)
                else:
                    form.add_error(field=None, error=u"Senhas diferentes.")
                    return self.form_invalid(form)
            else:
                form.add_error(
                    field=None, error=u"Não foi possivel trocar a senha. Formulário inválido.")
                return self.form_invalid(form)
        else:
            form.add_error(
                field=None, error=u"O link usado para a troca de senha não é válido ou expirou, por favor tente enviar novamente.")
            return self.form_invalid(form) 
开发者ID:thiagopena,项目名称:djangoSIGE,代码行数:38,代码来源:views.py

示例6: password_reset_confirm

# 需要导入模块: from django.contrib.auth.tokens import default_token_generator [as 别名]
# 或者: from django.contrib.auth.tokens.default_token_generator import check_token [as 别名]
def password_reset_confirm(request, uidb64, token):
    """REST API reset password confirm"""
    serializer = PasswordSerializer(data=request.data)
    serializer.is_valid(raise_exception=True)
    uid = force_text(urlsafe_base64_decode(uidb64))
    try:
        user = User.objects.get(pk=uid)
    except User.DoesNotExist:
        user = None
    if user is not None and default_token_generator.check_token(user, token):
        user.set_password(serializer.validated_data.get('password'))
        user.save()
    return Response({}, status=status.HTTP_201_CREATED) 
开发者ID:CodeForPoznan,项目名称:volontulo,代码行数:15,代码来源:api.py

示例7: recupera_password_conferma

# 需要导入模块: from django.contrib.auth.tokens import default_token_generator [as 别名]
# 或者: from django.contrib.auth.tokens.default_token_generator import check_token [as 别名]
def recupera_password_conferma(request, uidb64=None, token=None,
                           template='base_recupero_password_conferma.html',
                           contesto_extra=None):
    assert uidb64 is not None and token is not None  # checked by URLconf
    try:
        # urlsafe_base64_decode() decodes to bytestring on Python 3
        uid = force_text(urlsafe_base64_decode(uidb64))
        utente = Utenza.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, Utenza.DoesNotExist):
        utente = None

    if utente is not None and default_token_generator.check_token(utente, token):
        link_valido = True
        titolo = 'Inserisci una nuova password'
        if request.method == 'POST':
            modulo = ModuloImpostaPassword(utente, request.POST)
            if modulo.is_valid():
                modulo.save()
                return HttpResponseRedirect(reverse('recupero_password_completo'))
        else:
            modulo = ModuloImpostaPassword(utente)
    else:
        link_valido = False
        modulo = None
        titolo = 'Errore nell\'impostazione della nuova password'
    contesto = {
        'modulo': modulo,
        'titolo': titolo,
        'link_valido': link_valido,
        "scadenza_token": django_settings.PASSWORD_RESET_TIMEOUT_DAYS * 24
    }
    if contesto_extra is not None:
        contesto.update(contesto_extra)

    return TemplateResponse(request, template, contesto) 
开发者ID:CroceRossaItaliana,项目名称:jorvik,代码行数:37,代码来源:viste.py


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