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


Python signing.Signer类代码示例

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


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

示例1: surveyAnswerSubmit

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,代码行数:26,代码来源:views.py

示例2: form_type

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,代码行数:33,代码来源:multiuploader.py

示例3: Home

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,代码行数:32,代码来源:views.py

示例4: Edit_Deck

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,代码行数:35,代码来源:views.py

示例5: index

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,代码行数:28,代码来源:views.py

示例6: email_verify_and_update

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,代码行数:29,代码来源:views.py

示例7: get_sign_vigencia

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,代码行数:7,代码来源:compilacao_filters.py

示例8: make_paypal_url

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,代码行数:25,代码来源:paypal.py

示例9: explain

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,代码行数:30,代码来源:views.py

示例10: form_valid

 def form_valid(self, form):
     resp = super(EmailUserRegistrationView, self).form_valid(form)
     user = self.object 
     signer = Signer()
     
     site = Site.objects.get(id=settings.SITE_ID)
             
     ref_url = 'http://{}/confirm-email/{}/{}/'.format(site.domain, user.id, signer.signature(user.email))
     
     txt_body = render_to_string(self.email_text_template_name,
                                 {'reference': ref_url, 'site': site.name})
 
     html_body = render_to_string(self.email_html_template_name,
                                 {'reference': ref_url, 'site': site.name})
     from_email = '{}{}'.format(settings.DEFAULT_FROM_EMAIL, site.domain)
     
     send_mail(
         recipient_list = [user.email],
         subject = 'Account activation on the website online-polling.com', 
         message=txt_body,
         html_message=html_body,
         from_email = from_email ,
         fail_silently = True,
     )
     #save early voting
     try:
         sch = self.request.session.pop('anonym_vote') #early voting
         ch = Choice.objects.get(pk=sch)
         user_choice = CUserChoice(choice=ch, cuser=user, date_vote = timezone.now())
         user_choice.save()
     except:
         pass
     return resp
开发者ID:Cojuvy,项目名称:mysite,代码行数:33,代码来源:views.py

示例11: authenticate

 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,代码行数:7,代码来源:backend.py

示例12: setUpTestData

    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,代码行数:60,代码来源:tests.py

示例13: dispatch

    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,代码行数:26,代码来源:public_event_views.py

示例14: _generate_timestamp

 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,代码行数:7,代码来源:forms.py

示例15: generate_unsubscribe_url

def generate_unsubscribe_url(user, email_type):
    signer = Signer()
    url_path = "/account/settings/unsubscribe/{email_type}/{token}"
    action = '|'.join([str(user.id), user.username, 'unsubscribe', email_type])
    token = signer.sign(action)
    path = url_path.format(email_type=email_type, token=token)
    return make_path_absolute(path)
开发者ID:reverie,项目名称:jotleaf.com,代码行数:7,代码来源:emails.py


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