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


Python Signer.sign方法代码示例

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


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

示例1: Shared_Decks

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [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

示例2: form_type

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
def form_type(context, form_type):
    mu_forms = getattr(settings, "MULTIUPLOADER_FORMS_SETTINGS", DEFAULTS.MULTIUPLOADER_FORMS_SETTINGS)

    signer = Signer()

    if form_type:
        import warnings

        if form_type == "" or form_type not in mu_forms:
            if settings.DEBUG:
                warnings.warn(
                    "A {% form_type %} was used in a template but such form_type (%s) was not provided in settings, default used instead"
                    % form_type
                )

            return mark_safe(
                u"<div style='display:none'><input type='hidden' name='form_type' value='%s' /></div>"
                % signer.sign("default")
            )

        else:
            return mark_safe(
                u"<div style='display:none'><input type='hidden' name='form_type' value='%s' /></div>"
                % signer.sign(form_type)
            )
    else:
        # It's very probable that the form_type is missing because of
        # misconfiguration, so we raise a warning

        if settings.DEBUG:
            warnings.warn("A {% form_type %} was used in a template but form_type was not provided")

        return mark_safe(u"")
开发者ID:encolpe,项目名称:apetizer,代码行数:35,代码来源:multiuploader.py

示例3: addDefaultScoreQuestion

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
def addDefaultScoreQuestion(request):
    '''
        增加一个默认结构的问答题,提供给前台的新增问题按钮使用。
    '''
    # 检查用户是否登录,并读取session中的用户信息
    if USER_SESSION_NAME not in request.session.keys():
        return packageResponse(RESULT_CODE.ERROR, RESULT_MESSAGE.NO_LOGIN)
    user = request.session[USER_SESSION_NAME]

    # 检查是否提供了paper
    if 'paper' not in request.REQUEST.keys():
        return packageResponse(RESULT_CODE.ERROR, RESULT_MESSAGE.NO_ID)
    paperId = request.REQUEST['paper']

    # 调用问题新增处理过程
    requestData = {'paper': paperId, 'text': u'新增评分题,请填写(最长150字)', 'type': 'Score'}
    result = _questionAdd(requestData, user)
    if result['resultCode'] != 0:
        return dictToJsonResponse(result)
    questionId = result['questionId']

    # 对id进行数字签名
    signer = Signer()
    questionId = signer.sign(questionId)

    # 返回成功
    return packageResponse(RESULT_CODE.SUCCESS, RESULT_MESSAGE.SUCCESS, {'id': questionId})
开发者ID:xmduhan,项目名称:qisite,代码行数:29,代码来源:services.py

示例4: _generate_timestamp

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
 def _generate_timestamp(self):
     """
     Generate a new signed timestamp.
     """
     signer = Signer(salt=self.timestamp_signer_salt)
     timestamp = baseconv.base62.encode(int(time.time()))
     return signer.sign(timestamp)
开发者ID:TamiaLab,项目名称:carnetdumaker,代码行数:9,代码来源:forms.py

示例5: dispatch

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
    def dispatch(self, request, *args, **kwargs):
        self.event = get_object_or_404(Event, pk=self.kwargs['pk'])
        if self.admin:
            self.person = get_object_or_404(Person, id=self.kwargs.get('person_id', None))
        else:
            self.token = self.kwargs.get('token', None)
            if self.token:
                self.person = person_from_token(self.token, Person)
            else:
                self.person_id = self.kwargs.get('person_id', None)
                if not self.person_id:
                    self.person = person_from_user(request, raiseException=False)
                    if self.person:
                        self.person_id = self.person.id
                if self.person_id:
                    signer = Signer()
                    token = signer.sign(self.person_id)
                    return redirect('events:register_token', token=token, pk=self.event.pk)

        # Get here with a token and self.person set OR self.person=None which requires a login
        self.participants = Participant.objects.filter(
            event=self.event).order_by('person__first_name', 'person__last_name')
        parts = self.participants.filter(person=self.person)
        if parts:
            self.participant = parts[0]
        return super().dispatch(request, *args, **kwargs)
开发者ID:ianastewart,项目名称:cwltc-admin,代码行数:28,代码来源:public_event_views.py

示例6: manifest_url

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
def manifest_url(key=None):
    if not key:
        return reverse('cache_manifest')
    else:
        signer = Signer(sep='_', salt='manifesto')
        signed_key = signer.sign(key)
        return reverse('cache_manifest_keyed', args=[signed_key])
开发者ID:adamcharnock,项目名称:manifesto,代码行数:9,代码来源:manifesto.py

示例7: index

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
def index(request):
	N = 10
	file_name = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(N))
	file_url = '/CodeTable_app/' + file_name + '/'
	signer = Signer()
	value = signer.sign(file_name)
	# print 'Result : ', value, file_name

	response = HttpResponseRedirect(file_url)

	c = Code(code_id = file_name, last_edited = datetime.now(), code_actual = "")
	c.save()

	if 'key' in request.COOKIES:
		key = request.COOKIES.get('key')
		# print 'yay'

	else:
		key =''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(20))
		response.set_cookie('key', key)
		# print 'no'

	allowed_key = [key]
	session = Session(code_id = file_name)
	session.setlist(allowed_key)
	session.save()

	return response
开发者ID:aman-iitj,项目名称:CodeTable,代码行数:30,代码来源:views.py

示例8: View_Deck

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [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

示例9: explain

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [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

示例10: get_sign_vigencia

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
def get_sign_vigencia(value):
    string = "%s,%s,%s" % (
        value.ta_publicado_id if value.ta_publicado_id else 0,
        value.inicio_vigencia,
        value.fim_vigencia)
    signer = Signer()
    return signer.sign(str(string))
开发者ID:interlegis,项目名称:sapl,代码行数:9,代码来源:compilacao_filters.py

示例11: authenticate

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
 def authenticate(self, hash, pk):
     user = User.objects.get(pk=pk)
     signer = Signer()
     value = signer.sign(user.username)
     if value.split(":")[1] == hash:
         return user
     return None
开发者ID:danieka,项目名称:churchplanner,代码行数:9,代码来源:backend.py

示例12: Home

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
def Home(request):
    form = None
    deck_list = []
    if request.user.is_authenticated:
        user_id = request.user.id
        signer = Signer(request.user.id)
        #new deck form
        if request.method == "POST":
            form = NewDeck(request.POST)
            if form.is_valid():
                deck = form.save(commit=False)
                deck.user_id = user_id
                deck.save()
                return HttpResponseRedirect('/')
        else:
            form = NewDeck(initial={'user' : request.user.id})
        #grab all decks associated with a user order by descending date created
        decks = Deck.objects.filter(user_id=user_id, deleted_flag = 0).order_by('-date_created')
        
        
        for deck in decks:
            deck_list.append({
                            "deck_id" : signer.sign(deck.deck_id), 
                            "deck_name" : deck.deck_name, 
                            "share" : deck.share_flag
                            })        

    context = {
        "form"      : form,
        "deck_list" : deck_list,
    }
    return render(request, "landing/home.html", context)
开发者ID:zero14777,项目名称:My-Stuff,代码行数:34,代码来源:views.py

示例13: email_verify_and_update

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
def email_verify_and_update(request):
    """If the verification_key is correct, change the user email."""
    # check the verification_key
    name = request.user.name
    new_email = request.GET.get('new_email')
    signer = Signer()
    expected_verification_key = signer.sign(name + new_email).split(':')[1]

    if expected_verification_key == request.GET.get('verification_key'):

        # now update email
        user_id = request.user.id

        # if we dont set password to None we get a dict-key error in api/keystone
        api.keystone.user_update(
            request,
            user_id,
            name=new_email,
            password=None)

        msg = 'Email changed succesfully.'
        messages.success(request, msg)
    else:
        msg = 'Invalid verification key. Email not updated.'
        messages.error(request, msg)

    # redirect user to settings home
    response = redirect('horizon:settings:multisettings:index')
    return response
开发者ID:rnmanhon,项目名称:mqtt.sec,代码行数:31,代码来源:views.py

示例14: setUpTestData

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
    def setUpTestData(cls):
        """Prepare data fro test cases.

            1. Create new organization.
            2. Create invitation.
        """
        cls.client = Client()
        cls.org = Organization.objects.create(
            name="My Organization 1",
            email="[email protected]",
            phone="887555473",
            address="Hawai, Janosikova 4",
            created=datetime.now())
        cls.org.save()
        cls.inv = Invitation.objects.create(
            reg_uuid=str(uuid4()).replace('-', ''),
            user_name='Invited User',
            email='[email protected]',
            phone='1230000',
            organization=cls.org,
            superuser=False,
            # default_file_permissions=1,
            can_invite=True,
            expiration=datetime.now()+timedelta(days=1),
            secret_code=str(uuid4())[:5])
        cls.inv.save()
        signer = Signer()
        register_data = {
            'signature': signer.sign(cls.inv.reg_uuid),
            'user_name': cls.inv.user_name,
            'email': cls.inv.email,
            'login_pwd': 'password',
            'c_login_pwd': 'password',
            'key_pwd': 'password',
            'c_key_pwd': 'password',
            'phone': cls.inv.phone,
            'address': 'Janosikova 4, Hawai',
            'pub_key': _public_key,
            'priv_key': _private_key,
            'organization': 'someorg',
            'superuser': cls.inv.superuser,
            'can_invite': cls.inv.can_invite,
            'can_view': cls.inv.can_view,
            'can_comment': cls.inv.can_comment,
            'can_sign': cls.inv.can_sign,
            'can_modify': cls.inv.can_modify,
            'can_remove': cls.inv.can_remove,
            # 'default_file_permissions': permissions._permissions,
            'csr': _csr,
        }
        cls.get_access_response = cls.client.get(
            '/register/{}/'.format(cls.inv.reg_uuid))
        cls.invalid_code_response = cls.client.post(
            '/register/{}/'.format(cls.inv.reg_uuid),
            {'secret_code': '0000'})
        cls.valid_code_response = cls.client.post(
            '/register/{}/'.format(cls.inv.reg_uuid),
            {'secret_code': cls.inv.secret_code})
        cls.register_response = cls.client.post(
            '/register/submit/', register_data)
开发者ID:peterlacko,项目名称:thesis,代码行数:62,代码来源:tests.py

示例15: make_paypal_url

# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import sign [as 别名]
def make_paypal_url(request, payment):

    signer = Signer()
    item_number = signer.sign(unicode(payment.id))

    params = {"cmd": "_xclick",
              "business": settings.ARTSHOW_PAYPAL_ACCOUNT,
              "undefined_quantity": "0",
              "item_name": "Art Show Payment from " + payment.artist.artistname(),
              "item_number": item_number,
              "amount": unicode(payment.amount),
              "shipping": "0",
              "no_shipping": "1",
              "return": request.build_absolute_uri(reverse("artshow.manage.payment_made_paypal",
                                                           args=(payment.artist_id,))),
              "cancel_return": request.build_absolute_uri(
                  reverse("artshow.manage.payment_cancelled_paypal",
                          args=(payment.artist_id,)) + "?" + urlencode({"item_number": item_number})),
              "currency_code": "USD",
              "bn": "PP-BuyNow",
              "charset": "UTF-8",
              "notify_url": request.build_absolute_uri(reverse(ipn_handler)),
              }

    return settings.ARTSHOW_PAYPAL_URL + "?" + urlencode(params)
开发者ID:chmarr,项目名称:artshow-jockey,代码行数:27,代码来源:paypal.py


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