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


Python http.urlsafe_base64_decode方法代码示例

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


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

示例1: mutate_and_get_payload

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [as 别名]
def mutate_and_get_payload(cls, input, context, info):
        Model = UserModel

        try:
            uid = force_text(uid_decoder(input.get('id')))
            user = Model.objects.get(pk=uid)
        except (TypeError, ValueError, OverflowError, Model.DoesNotExist):
            raise Exception('uid has an invalid value')

        data = {
            'uid': input.get('id'),
            'token': input.get('token'),
            'new_password1': input.get('password'),
            'new_password2': input.get('password')
        }

        reset_form = SetPasswordForm(user=user, data=data)

        if not reset_form.is_valid():
            raise Exception("The token is not valid")

        reset_form.save()

        return ResetPassword(ok=True, user=user) 
开发者ID:morgante,项目名称:django-graph-auth,代码行数:26,代码来源:schema.py

示例2: get

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [as 别名]
def get(self, request, *_args, **kwargs):
        user = None
        try:
            uid = force_text(urlsafe_base64_decode(kwargs["uidb64"]))
            user = get_user_model().objects.get(id=int(uid))
        except (
            TypeError,
            ValueError,
            OverflowError,
            get_user_model().DoesNotExist,
        ) as e:
            print(e)
        if user is not None and email_confirmation_generator.check_token(
            user, kwargs["token"]
        ):
            user.is_active = True
            user.save()
            login(request, user)
            return redirect(reverse_lazy("status"))
        else:
            return HttpResponse("Activation link is invalid.") 
开发者ID:tamuhack-org,项目名称:Ouroboros,代码行数:23,代码来源:views.py

示例3: validate

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [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

示例4: activate

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [as 别名]
def activate(request, uid, token):
    try:
        uid = force_text(urlsafe_base64_decode(uid))
        user = User.objects.get(pk=uid)
        if request.user.is_authenticated and request.user != user:
            messages.warning(request, "Trying to verify wrong user. Log out please!")
            return redirect('root')
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        messages.warning(request, "This user no longer exists. Please sign up again!")
        return redirect('root')

    if account_activation_token.check_token(user, token):
        messages.success(request, "Email verified!")

        user.email_verified = True
        user.save()
        auth.login(request, user)
    else:
        messages.error(request, "Email verification url has expired. Log in so we can send it again!")
    return redirect('root') 
开发者ID:HackAssistant,项目名称:registration,代码行数:22,代码来源:views.py

示例5: password_reset_confirm

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [as 别名]
def password_reset_confirm(request, uid, token):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    """
    try:
        uid = force_text(urlsafe_base64_decode(uid))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        return TemplateResponse(request, 'password_reset_confirm.html', {'validlink': False})

    if password_reset_token.check_token(user, token):
        if request.method == 'POST':
            form = SetPasswordForm(request.POST)
            if form.is_valid():
                form.save(user)
                return HttpResponseRedirect(reverse('password_reset_complete'))
        form = SetPasswordForm()
    else:
        return TemplateResponse(request, 'password_reset_confirm.html', {'validlink': False})

    return TemplateResponse(request, 'password_reset_confirm.html', {'validlink': True, 'form': form}) 
开发者ID:HackAssistant,项目名称:registration,代码行数:24,代码来源:views.py

示例6: get

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [as 别名]
def get(self, request, *args, **kwargs):
        uidb64 = kwargs['uidb64']
        token = kwargs['token']
        try:
            uid = urlsafe_base64_decode(uidb64).decode()
            user = self.model.objects.get(id=uid)
        except(TypeError, ValueError, OverflowError, self.model.DoesNotExist):
            user = None
        if user is not None and account_activation_token.check_token(user, token):
            messages.info(request, _("Thanks for registering. You are now logged in."))
            user.is_active = True
            user.save()
            login(request, user)
            return HttpResponseRedirect(reverse("landing_page:home"))
        else:
            return render(request, 'registration/invalid_activation_link.html')


# TODO reactivate as soon as the bug is fixed
# TODO BUG does it work as intended again?
# TODO BUG sends wrong url for local (development) settings example.com != localhost:port 
开发者ID:iguana-project,项目名称:iguana,代码行数:23,代码来源:views.py

示例7: initial

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [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

示例8: get_user_from_uid

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [as 别名]
def get_user_from_uid(uid):
    if uid is None:
        raise ValidationError(_("uid is required!"))
    try:
        uid = urlsafe_base64_decode(uid)
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        raise ValidationError(_(u"Invalid uid %s") % uid)

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

示例9: dispatch

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [as 别名]
def dispatch(self, request, invite_idb64, token):
        invite_id = force_text(urlsafe_base64_decode(invite_idb64))
        invite = UserInvite.objects.filter(id=invite_id, token=token, is_used=False)
        if invite:
            return super(ActivateRole, self).dispatch(request, invite[0], invite_idb64, token)
        return HttpResponseRedirect(reverse('login')) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:8,代码来源:views.py

示例10: post

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [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

示例11: get_user

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [as 别名]
def get_user(self, uidb64):
        try:
            # urlsafe_base64_decode() decodes to bytestring
            uid = urlsafe_base64_decode(uidb64).decode()
            user = UserModel._default_manager.get(pk=uid)
        except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
            user = None
        return user 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:10,代码来源:views.py

示例12: urlsafe_base64_decode

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [as 别名]
def urlsafe_base64_decode(s):
        """
        Decodes a base64 encoded string, adding back any trailing equal signs that
        might have been stripped.
        """
        s = s.encode('utf-8')  # base64encode should only return ASCII.
        try:
            return base64.urlsafe_b64decode(s.ljust(len(s) + len(s) % 4, b'='))
        except (LookupError, BinasciiError) as e:
            raise ValueError(e) 
开发者ID:mishbahr,项目名称:django-users2,代码行数:12,代码来源:compat.py

示例13: activate_user

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [as 别名]
def activate_user(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except(TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None
    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.save()
        auth_messages.success(request, 'Thank you for your email confirmation. You can login to your account now.')
        return redirect('login')
    else:
        return HttpResponse('Activation link is invalid!') 
开发者ID:fresearchgroup,项目名称:Collaboration-System,代码行数:15,代码来源:views.py

示例14: password_reset_confirm

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [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

示例15: decode_uid

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlsafe_base64_decode [as 别名]
def decode_uid(pk):
    return force_text(urlsafe_base64_decode(pk)) 
开发者ID:sunscrapers,项目名称:djoser,代码行数:4,代码来源:utils.py


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