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


Python Signer.unsign方法代码示例

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


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

示例1: verify

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
 def verify(self):
     """
     Attempts to unsign the signature using the current `SECRET_KEY`. If
     unsigning fails, `SECRET_KEY` has changed, and the exception
     `django.core.signing.BadSignature` will be raised. If `SECRET_KEY_FILE`
     does not exist, `secretkey.errors.SecretKeyFileNotFound` will be
     raised.
     """
     secret_key = settings.SECRET_KEY
     signer = Signer(secret_key)
     signer.unsign(self.signed_value)
开发者ID:bendavis78,项目名称:django-secretkey,代码行数:13,代码来源:models.py

示例2: clean

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
    def clean(self):
        cleaned_data = super(ExternalURLForm, self).clean()
        signer = Signer()

        if self.errors:
            # if it's not a valid URL, no reason to do further validation
            return

        url = cleaned_data['ext_url']
        matched_whitelist = any((regex.match(url) for regex in EXTERNAL_URL_WHITELIST))

        if matched_whitelist:
            cleaned_data['validated_url'] = url

        elif 'signature' in cleaned_data:
            signed_url = "{ext_url}:{signature}".format(**cleaned_data)
            try:
                cleaned_data['validated_url'] = signer.unsign(signed_url)
            except BadSignature:
                raise ValidationError(_('Signature validation failed'),
                                      code='invalid')
        else:
            raise ValidationError(_('URL must either be allowed by '
                                    'settings.EXTERNAL_URL_WHITELIST '
                                    'or have a valid signature'),
                                  code='invalid')
开发者ID:m3brown,项目名称:cfgov-refresh,代码行数:28,代码来源:forms.py

示例3: catalogo

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def catalogo(request):
    try:
        lista = get_lista(request)
        cliente = request.user.cliente if request.user.is_authenticated() else None
        context = get_base_context(request=request)
        signer = Signer()
        signed_id = None
        
        if request.method == 'GET': 
            signed_id = request.GET.get('bien_id',0)        
        else:
            if 'add_to_cart_button' in request.POST:
                signed_id = request.POST.get('bien_id',0)
                add_to_cart(request)

        if signed_id:
            bien_id = int(signer.unsign(signed_id),0)
            if lista and (bien_id > 0):
                bien = lista.get_bienes(include_hidden=False, search_bien_id=bien_id, cliente=cliente)
                context['bien'] = bien
                context['impuesto'] = lista.impuesto
                atributos = models.BienYAtributo.objects.filter(bien__id=bien.id)
                context['atributos'] = atributos
    except AttributeError as e:
        return HttpResponseServerError(e)
    return render(request, 'catalogo.html', context)
开发者ID:jmaltube,项目名称:nebula,代码行数:28,代码来源:views.py

示例4: changeResestPassword

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def changeResestPassword(request):
    token = request.POST['token']
    if token:
        signer = Signer()
        try:
            original = signer.unsign(token)
        except BadSignature:
            print("Tampering detected!")
            return JsonResponse({'error' : 'token expired'})

        user = User.objects.filter(username=original).get()
        newPass = request.POST['password']
        user.password = make_password(newPass)
        user.save()
        user = authenticate(username=original, password=newPass)
        login(request, user)
        request.session['member_id'] = user.id
        request.session['username'] = user.username
        return JsonResponse({'success' : 'password changed for ' + user.username})
    else:
        if request.user.is_authenticated():
            me = request.user
            if check_password(request.POST['password0'], me.password):
                newPass = request.POST['password']
                me.password = make_password(newPass)
                me.save()
                me = authenticate(username=me.username, password=newPass)
                login(request, me)
                return JsonResponse({'success' : 'password changed for ' + me.username})
            else:
                return JsonResponse({'error' : 'current password doesn\'t match'})

    return JsonResponse({'error' : 'password not changed'})
开发者ID:geleouet,项目名称:PollEuro2016,代码行数:35,代码来源:views.py

示例5: Edit_Deck

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def Edit_Deck(request):
    if request.method == 'POST':
        deck_id_signed = request.POST.get('deck_id')
        deck_id = None
        signer = Signer(request.user.id)
        try:
        	deck_id = signer.unsign(deck_id_signed)
        except signing.BadSignature:
    		print("Tampering detected!!")
    		return HttpResponseRedirect('/')
        deck_name = request.POST.get('deck_name')
        user = request.POST.get('user')
        share_flag = request.POST.get('share_flag')
        if share_flag == 'false':
            share_flag = 0
        else:
            share_flag = 1
        data = {'user' : user, 'deck_name' : deck_name, "share_flag" : share_flag}
        deck = get_object_or_404(Deck, deck_id=deck_id)
        if deck.deck_name == deck_name:
            deck.share_flag = share_flag
            deck.save()
        else:
            form = NewDeck(data)
            if form.is_valid():

                #deck = get_object_or_404(Deck, deck_id=deck_id)
                deck.deck_name = deck_name
                deck.share_flag = share_flag
                deck.save()
            else:
                errors = form.errors
                return HttpResponse(json.dumps(errors))
    
    return HttpResponse(json.dumps({"success": "success"}))
开发者ID:zero14777,项目名称:My-Stuff,代码行数:37,代码来源:views.py

示例6: surveyAnswerSubmit

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def surveyAnswerSubmit(request):
    '''
    问卷批量提交服务
    '''

    # 读取surveyId
    surveyIdSigned = request.REQUEST.get('surveyId')
    if not surveyIdSigned:
        # raise Exception(RESULT_MESSAGE.NO_SURVEY_ID)  # 没有提供调查对象
        template = loader.get_template('www/answerFinished.html')
        context = RequestContext(request, {'title': u'出错', 'message': RESULT_MESSAGE.NO_SURVEY_ID, 'returnUrl': '/'})
        return HttpResponse(template.render(context))

    # 对调查标识的数据签名进行检查
    try:
        signer = Signer()
        surveyId = signer.unsign(surveyIdSigned)
    except:
        # raise Exception(RESULT_MESSAGE.BAD_SAGNATURE)  # 无效的数字签名
        template = loader.get_template('www/answerFinished.html')
        context = RequestContext(request, {'title': u'出错', 'message': RESULT_MESSAGE.BAD_SAGNATURE, 'returnUrl': '/'})
        return HttpResponse(template.render(context))

    # 调用提交控制器生成处理数据,并生成返回结果
    surveySubmitController = SurveySubmitController(request, surveyId)
    return surveySubmitController.process()
开发者ID:xmduhan,项目名称:qisite,代码行数:28,代码来源:views.py

示例7: unsign_purpose

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def unsign_purpose(signed_purpose):
    signer = Signer()
    try:
        val = signer.unsign(signed_purpose)
        return val[len(SALT):]
    except BadSignature:
        return None
开发者ID:stefanw,项目名称:froide,代码行数:9,代码来源:utils.py

示例8: Shared_Decks

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def Shared_Decks(request):
    u_id = request.GET.get('u_id')
    user = None
    user_name = None
    signer = Signer(request.user.id)
    try:
        user = signer.unsign(u_id)
    except signing.BadSignature:
        return HttpResponse(json.dumps({"Tampering": "bad signature"}))
    shared_decks = Deck.objects.filter(user_id = user, share_flag = 1, deleted_flag = 0)
    deck_list = []
    for deck in shared_decks:
        deck_list.append({
            "orig_deck_id" : signer.sign(deck.deck_id),
            "deck_name" : deck.deck_name,
            "share" : deck.share_flag,
        })
    form = NewDeck(initial={'user' : request.user.id})
    getname = User.objects.filter(id = user)
    for user_obj in getname:
        user_name = user_obj.username
    context = {
        "shared_user_id" : user,
        "shared_user_name" : user_name,
        "shared_decks" : deck_list,
        "clone_form" : form,
        "sign" : signer.sign(request.user.id)
    }
    return render(request, 'flash_cards/shared_profile.html', context)
开发者ID:zero14777,项目名称:My-Stuff,代码行数:31,代码来源:views.py

示例9: Study

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def Study(request):
    signer = Signer(request.user.id)
    deck_id_signed = request.GET.get('deck_id')
    deck_id = None
    deckname = ""
    card_list = []
    current_user_id = request.user.id
    try:
        deck_id = signer.unsign(deck_id_signed)
    except signing.BadSignature:
        print "Tampering Detected! Study"
        return HttpResponseRedirect('/')
    deck = Deck.objects.filter(deck_id = deck_id, deleted_flag = 0)
    try:
        deckname = deck[0].deck_name
        deck_creator_id = deck[0].user_id
    except IndexError:
        deckname = ""
    cards = Card.objects.filter(deck_id = deck_id, deleted_flag = 0).order_by('-date_created')
    for card in cards:
        card_list.append({
            "card_id" : card.card_id,
            "front" : card.front,
            "back" : card.back,
            })
    context = {
        "deckname" : deckname,
        "card_list" : card_list,
        "deck_id_signed" : deck_id_signed,
        "deck_creator_id" : deck_creator_id,
        "current_user_id" : current_user_id,

    }

    return render(request, 'flash_cards/study.html', context)
开发者ID:zero14777,项目名称:My-Stuff,代码行数:37,代码来源:views.py

示例10: View_Deck

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def View_Deck(request):
    deck_id_signed = request.GET.get('deck_id')
    deck_id = None
    card_list =[]
    signer = Signer(request.user.id)
    try:
        deck_id = signer.unsign(deck_id_signed)
    except signing.BadSignature:
        print("Tampering detected! View deck")
        return HttpResponseRedirect('/')
    form = NewCard(initial={'deck' : request.GET.get('deck_id')})
    cards = Card.objects.filter(deck_id=deck_id, deleted_flag = 0).order_by('-date_created')
    deck = Deck.objects.filter(deck_id=deck_id, deleted_flag = 0)
    print "here"
    deck_name = ""
    try:
        deck_name = deck[0].deck_name
    except IndexError:
        deck_name = ""
    for card in cards:
        card_list.append({
            "card_id" : card.card_id,
            "front" : card.front,
            "back" : card.back,
            }) 
    upload_form = UploadFile(initial={"deck_id" : signer.sign(deck_id)})
    context = {
        "upload_form" : upload_form,
        "form" : form,
        "card_list" : card_list,
        "deck_id" : deck_id_signed,
        "deck_name" : deck_name, 
    }
    return render(request, 'flash_cards/view_deck.html', context)
开发者ID:zero14777,项目名称:My-Stuff,代码行数:36,代码来源:views.py

示例11: _custListItemDelete

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def _custListItemDelete(requestData, user):
    '''
    问卷删除的具体处理函数
    '''
    # 检查是否提供了id
    keys = requestData.keys()
    if 'id' not in keys:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.NO_ID)
    idSigned = requestData['id']

    # 对id进行数字签名的检查
    try:
        signer = Signer()
        id = signer.unsign(idSigned)
    except BadSignature:
        # 篡改发现处理
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.BAD_SAGNATURE)

    # 检查对象是否还存在,并将对象锁定
    custListListItem = CustListItem.objects.filter(id=id).select_for_update()
    if len(custListListItem) == 0:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.OBJECT_NOT_EXIST)
    custListItem = custListListItem[0]

    # 检查当前用户是否有权限修改
    if custListItem.createBy.id != user.id:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.NO_PRIVILEGE)

    # 执行删除
    custListItem.delete()

    # 返回成功
    return packageResult(RESULT_CODE.SUCCESS, RESULT_MESSAGE.SUCCESS)
开发者ID:xmduhan,项目名称:qisite,代码行数:35,代码来源:services.py

示例12: _paperDelete

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def _paperDelete(requestData, user):
    # 检查是否提供了id
    keys = requestData.keys()
    if 'id' not in keys:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.NO_ID)
    idSigned = requestData['id']

    # 对id进行数字签名的检查
    try:
        signer = Signer()
        id = signer.unsign(idSigned)
    except BadSignature:
        # 篡改发现处理
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.BAD_SAGNATURE)

    # 检查对象是否还存在,并将对象锁定
    paperList = Paper.objects.filter(id=id).select_for_update()
    if len(paperList) == 0:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.OBJECT_NOT_EXIST)
    paper = paperList[0]

    # 检查当前用户是否有权限修改
    if paper.createBy.id != user.id:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.NO_PRIVILEGE)

    # 执行删除
    paper.delete()

    # 返回成功
    return packageResult(RESULT_CODE.SUCCESS, RESULT_MESSAGE.SUCCESS)
开发者ID:xmduhan,项目名称:qisite,代码行数:32,代码来源:services.py

示例13: _surveyDelete

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def _surveyDelete(requestData, user):
    '''
    问卷删除的具体处理函数
    '''
    # 检查是否提供了id
    keys = requestData.keys()
    if 'id' not in keys:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.NO_ID)
    idSigned = requestData['id']

    # 对id进行数字签名的检查
    try:
        signer = Signer()
        id = signer.unsign(idSigned)
    except BadSignature:
        # 篡改发现处理
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.BAD_SAGNATURE)

    # 检查对象是否还存在,并将对象锁定
    surveyList = Survey.objects.filter(id=id).select_for_update()
    if len(surveyList) == 0:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.OBJECT_NOT_EXIST)
    survey = surveyList[0]

    # 检查当前用户是否有权限修改
    if survey.createBy.id != user.id:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.NO_PRIVILEGE)

    # 执行删除
    # 调查的删除不是直接删除,而是将状态改为P,有些信息还要以备后查
    survey.state = 'P'
    survey.save()

    # 返回成功
    return packageResult(RESULT_CODE.SUCCESS, RESULT_MESSAGE.SUCCESS)
开发者ID:xmduhan,项目名称:qisite,代码行数:37,代码来源:services.py

示例14: explain

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def explain(request):
    # Make sure that the user can only submit an explanation for the random word we picked
    signer = Signer()
    if request.method == 'POST':
        form = ExplainForm(request.POST)
        if form.is_valid():
            word_id = signer.unsign(form.cleaned_data['word_signed'])
            word = Word.objects.get(pk=word_id)
            explanation = Explanation(
                        word=word,
                        explanation= form.cleaned_data['explanation'],
                        author = request.user,
                        )
            explanation.save()
            messages.success(request, u"Vielen Dank für Deine Erklärung zu „%s“!" % word.lemma)
            return redirect('index')
    else:
        try:
            word = Word.random(player = request.user)
            form = ExplainForm(initial = {'word_signed': signer.sign(word.id)})
        except NotEnoughWordsException:
            messages.error(request, u"Leider gibt es nicht genügend Wörter. Motiviere deine Freunde, ein paar neue Wörter einzugeben!")
            return redirect('index')


    context = {
        'word': word,
        'form': form,
    }
    return render(request, 'nbip/explain.html', context)
开发者ID:entropia,项目名称:no-bot-is-perfect,代码行数:32,代码来源:views.py

示例15: process_ipn

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import unsign [as 别名]
def process_ipn(sender, **kwargs):

    query = kwargs['query']
    payment_id = None

    try:
        verify_url = settings.ARTSHOW_PAYPAL_URL + "?cmd=_notify-validate&" + query
        paypal_logger.debug("requesting verification from: %s", verify_url)
        pipe = urlopen(verify_url)
        text = pipe.read(128)

        if text != "VERIFIED":
            raise IPNProcessingError("Paypal returned %s for verification" % text)

        params = parse_qs(query)
        paypal_logger.info("validated PayPal IPN: %s", repr(params))

        txn_type = params['txn_type'][0]
        if txn_type != "web_accept":
            raise IPNProcessingError("txn_type is %s not web_accept" % txn_type)

        item_number = params['item_number'][0]
        payment_status = params['payment_status'][0]
        amount_gross = params['mc_gross'][0]
        amount_gross = Decimal(amount_gross)
        payer_email = params['payer_email'][0]
        payment_date_str = params['payment_date'][0]

        payment_date = convert_date(payment_date_str)

        if payment_status != "Completed":
            raise IPNProcessingError("payment status is %s != Completed" % payment_status)

        signer = Signer()
        payment_id = signer.unsign(item_number)
        payment = Payment.objects.get(id=payment_id)

        if payment.payment_type_id != settings.ARTSHOW_PAYMENT_PENDING_PK:
            if payment.payment_type_id == settings.ARTSHOW_PAYMENT_RECEIVED_PK and payment.amount == amount_gross:
                paypal_logger.info("additional notification received for payment id %s. this is normal", payment_id)
                return
            raise IPNProcessingError("payment is not Payment Pending state")

        if payment.amount != amount_gross:
            paypal_logger.warning("payment is being changed from %s to %s", payment.amount, amount_gross)

        paypal_logger.info("marking payment received. payment id: %s  amount: %s  paypal email: %s",
                           payment_id, amount_gross, payer_email)

        payment.amount = amount_gross
        payment.payment_type_id = settings.ARTSHOW_PAYMENT_RECEIVED_PK
        payment.description = "Paypal " + payer_email
        payment.date = payment_date
        payment.save()

    except Exception, x:
        paypal_logger.error("Error when getting validation for: %s", query)
        if payment_id:
            paypal_logger.error("... during processing of payment_id: %s", payment_id)
        paypal_logger.error("%s", x)
开发者ID:chmarr,项目名称:artshow-jockey,代码行数:62,代码来源:paypal.py


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