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


Python TimestampSigner.unsign方法代码示例

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


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

示例1: reset

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
def reset(request, token=None):
    error_message = None
    signer = TimestampSigner()
        
    reset_token_form = ResetTokenForm(request.POST or None)
    
    # Token not passed through URL parameter.
    if token is None and reset_token_form.is_valid():
        token = reset_token_form.cleaned_data['token']
    
    
    if token is not None:
        encrypted_token = None
        # The token might be a shortcode. First try to look up a matching shortcode.
        try:
            shortcode = TextMessageShortCode.objects.get(code=token)
            encrypted_token = shortcode.token
        except TextMessageShortCode.DoesNotExist:
            encrypted_token = token
            
        try:
            # max_age is in seconds, so 1 hr.
            psu_uuid = signer.unsign(encrypted_token, max_age=60*60)
            
            # Verify psu_uuid, authenticate user, redirect to "new student" version of MyInfo.
            user = auth.authenticate(psu_uuid = psu_uuid, request=request)
            
            if user is not None:
                auth.login(request, user)

                # Now they need to reset their password.
                (oam_status, _) = OAMStatusTracker.objects.get_or_create(psu_uuid = request.session['identity']['PSU_UUID'])
                oam_status.set_password = False
                oam_status.save()

                return HttpResponseRedirect(reverse('AccountPickup:next_step'))
            
            logger.error("service=myinfo psu_uuid={0} error=\"Password token decrypted succesfully but unable to authenticate.\"".format(psu_uuid))
            error_message = "There was an internal error. Please contact the helpdesk for support."
        except SignatureExpired:
            udc_id = signer.unsign(token)
            # Too slow!
            logger.info("service=myinfo psu_uuid={0} error=password_timeout".format(udc_id))
            error_message = "The password reset expired. Please try again."
        except BadSignature:
            logger.info("service=myinfo token={0} error=\"An invalid reset token was passed to OAM PasswordReset\"")
            error_message = "There was an internal error. Please contact the helpdesk for support."
    
        # Something went wrong, forward them back to the password reset link page.  
        if error_message is None:
            error_message = "There was an internal error. Please contact the helpdesk for support."
            logger.debug("Reached end of key signing attempt without an error message for token: {0}".format(token))

    return render(request, 'PasswordReset/verification.html', {'form' : reset_token_form, 'error' : error_message,})
开发者ID:kfarr2,项目名称:myinfo,代码行数:56,代码来源:views.py

示例2: check_token

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
 def check_token(self, request):
     token = request.GET.get('token')
     if token is None:
         return None
     original = '%s:%s' % (self.get_absolute_file_url(), token)
     signer = TimestampSigner()
     try:
         signer.unsign(original, max_age=settings.FOI_MEDIA_TOKEN_EXPIRY)
     except SignatureExpired:
         return None
     except BadSignature:
         return False
     return True
开发者ID:stefanw,项目名称:froide,代码行数:15,代码来源:attachment.py

示例3: find

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
def find(request, token):
    try:
        signer = TimestampSigner(key=request.session.session_key, sep=':')
        id = b64_decode(signer.unsign(token, max_age=Task.TIMEOUT).encode('utf-8'))
        return Task.status(id)
    except:
        return None
开发者ID:jmartign,项目名称:vac-templater,代码行数:9,代码来源:__init__.py

示例4: find

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
def find(request, token):
    try:
        signer = TimestampSigner(key=request.session.session_key, sep=':')
        id = b64_decode(signer.unsign(token, max_age=86400).encode('utf-8'))
        return AsyncResult(id)
    except:
        return None
开发者ID:BillTheBest,项目名称:varnish-bans-manager,代码行数:9,代码来源:__init__.py

示例5: check_token

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
def check_token(request, answer, token):
    payload = hashlib.sha1('{}:{}'.format(request.session.session_key, answer.pk).encode()).hexdigest()
    signer = TimestampSigner()
    try:
        return payload == signer.unsign(token, max_age=3600 * 24)
    except BadSignature:
        return False
开发者ID:FlaviaBastos,项目名称:pretix,代码行数:9,代码来源:safedownload.py

示例6: lookup

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
    def lookup(self, signed):
        if signed is None:
            raise NonceException("No nonce was provided.")

        signer = TimestampSigner()
        try:
            payload = signer.unsign(signed, max_age=NONCE_MAX_AGE)
        except BadSignature:
            raise NonceException("The nonce signature was invalid.")
        except SignatureExpired:
            raise NonceException("The nonce has expired.")

        nonce, user_id = payload.split(":")

        User = get_user_model()
        user = User.objects.get(pk=user_id) if user_id else None

        nonce_list = list(Nonce.objects.filter(key=nonce)[:1])

        if nonce_list:
            nonce_obj = nonce_list[0]
            if nonce_obj.user == user:
                return nonce_obj
            else:
                raise NonceException("The current user does not have access to the specified nonce.")
        else:
            return Nonce(key=nonce, user=user)
开发者ID:chalkchisel,项目名称:django-uploadifive,代码行数:29,代码来源:models.py

示例7: confirmar_permiso

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
def confirmar_permiso(request):
    """
    ## Confirma un permiso enviado por la url

    Estado=Aprobado
    http://127.0.0.1:8000/confirmar/permiso/?token=4:1ay4mm:xeXW4JDTQqU3JYtVC-l_He1gT08&estado=1

    Estado=No Aprobado
    http://127.0.0.1:8000/confirmar/permiso/?token=4:1ay4mm:xeXW4JDTQqU3JYtVC-l_He1gT08&estado=0

    La utilidad de esta liibreria es para otorgar un permiso via email
    """
    token_mail = request.GET.get("token")
    estado = True if request.GET.get("estado") == "1" else False
    print estado
    print token_mail
    signer = TimestampSigner(salt="4g3t1c")
    try:
        pk_dpermiso = signer.unsign(token_mail, max_age=3600*1)
        designacion_permiso = DesignacionPermiso.objects.filter(pk=pk_dpermiso, token_mail=token_mail, token_confirmation_date__isnull=True)
        if designacion_permiso:
            designacion_permiso.update(aprobado=estado, token_confirmation_date=timezone.now())
            return HttpResponse("El permiso fue aprobado satisfactoriamente")
        else:
            return HttpResponse("El permiso ya fue confirmado")
    except signing.SignatureExpired:
        return HttpResponse("La clave del mensaje a expirado")
    except signing.BadSignature:
        return HttpResponse("Firma de Mensaje Incorrecto")
开发者ID:Marcelo1180,项目名称:agetic_rrhh,代码行数:31,代码来源:views.py

示例8: find_temporary_file

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
def find_temporary_file(token):
    signer = TimestampSigner(sep=':')
    filename, attachment_filename, mimetype = b64_decode(signer.unsign(
        token, max_age=TEMPORARY_FILE_TTL).encode('utf-8')).split(',')
    return (
        secure_join(settings.MEDIA_ROOT, 'temporary', filename),
        attachment_filename,
        mimetype,
    )
开发者ID:allenta,项目名称:varnish-bans-manager,代码行数:11,代码来源:__init__.py

示例9: restore_password

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
 def restore_password(self, inp):
     key = self.user.username + ":" + inp
     signer = TimestampSigner()
     try:
         x = signer.unsign(key, max_age=60*5)
         if x == self.user.username:
             return True
     except (SignatureExpired, BadSignature):
         pass
     return False
开发者ID:redlolgeerf,项目名称:draftwatcher,代码行数:12,代码来源:models.py

示例10: unsign_user_id

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
def unsign_user_id(b64_user_id, max_age=None):
    try:
        id_signer = TimestampSigner()
        unencoded_user_id = base64.urlsafe_b64decode(b64_user_id.encode('utf-8')).decode('utf-8')
        signed = id_signer.unsign(unencoded_user_id, max_age)
        return signed.split(':', 1)[0]

    except Exception as e:
        print(e)
        return None
开发者ID:devosray,项目名称:pinocchio,代码行数:12,代码来源:userFunctions.py

示例11: advanced_click_register

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
def advanced_click_register(request, ad_identifier):
    signer = TimestampSigner()
    try:
        ad_pk = signer.unsign(ad_identifier)
    except BadSignature:
        raise Http404
    advert = get_object_or_404(Advertisement, pk=ad_pk)

    advert.clicked()

    return HttpResponseRedirect(advert.url)
开发者ID:wdq,项目名称:OpenAds,代码行数:13,代码来源:views.py

示例12: dispatch

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
	def dispatch(self, request, *args, **kwargs):
		'''
		'''
		signer = TimestampSigner()
		try:
			value = request.get_signed_cookie('recovery_key')
			self.value = signer.unsign(value, max_age=self.max_age)
		except:
			return HttpResponseForbidden('This page is expired')
		else:
			return super(SetNewPassword, self).dispatch(request, *args, **kwargs)
开发者ID:Loki88,项目名称:django-Spin,代码行数:13,代码来源:SetNewPassword.py

示例13: get

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
    def get(self, request, *args, **kwargs):
        signer = TimestampSigner()
        try:
            ad_pk = signer.unsign(kwargs["ad_identifier"])
        except BadSignature:
            raise Http404
        advert = get_object_or_404(Advertisement, pk=ad_pk)

        advert.clicked()

        return HttpResponseRedirect(advert.url)
开发者ID:OpenAds,项目名称:OpenAds,代码行数:13,代码来源:__init__.py

示例14: is_valid

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
    def is_valid(self):
        if self.force_expiry:
            return False

        signer = TimestampSigner()

        try:
            username = signer.unsign(self.token, max_age=self.expiry_seconds)
        except (BadSignature, SignatureExpired):
            return False

        return username == self.user.username
开发者ID:hloganathan,项目名称:secondhand,代码行数:14,代码来源:models.py

示例15: returned_wrapper

# 需要导入模块: from django.core.signing import TimestampSigner [as 别名]
# 或者: from django.core.signing.TimestampSigner import unsign [as 别名]
 def returned_wrapper(request, *args, **kwargs):
     if request.method == "POST":
         code = request.POST.get('code', None)
         if code is None:
             code = request.GET.get('code', None)
     else:
         code = request.GET.get('code', None)
     if code:
         value = base64.b64decode(code)
         signer = TimestampSigner()
         try:
             username = signer.unsign(value, ONE_DAY)
             INFO_LOG.info(gen_info_msg(request, action='链接正常', code_url=request.path, valid=True, username=username))
             return func(request, *args, **kwargs)
         except (SignatureExpired, BadSignature, TypeError), e:
             username = signer.unsign(value)
             if isinstance(e, SignatureExpired):
                 messages.error(request, '链接已失效')
                 INFO_LOG.info(gen_info_msg(request, action=u'链接已失效', code_url=request.path, valid=False, username=username))
             elif isinstance(e, BadSignature):
                 messages.error(request, '链接被篡改')
                 INFO_LOG.info(gen_info_msg(request, action=u'链接被篡改', code_url=request.path, valid=False, username=username))
             return HttpResponseRedirect(settings.LOGIN_URL)
开发者ID:WesleyDevLab,项目名称:gather,代码行数:25,代码来源:decorators.py


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