本文整理汇总了Python中django.core.signing.Signer.signature方法的典型用法代码示例。如果您正苦于以下问题:Python Signer.signature方法的具体用法?Python Signer.signature怎么用?Python Signer.signature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.signing.Signer
的用法示例。
在下文中一共展示了Signer.signature方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: form_valid
# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import signature [as 别名]
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
示例2: _get_signature
# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import signature [as 别名]
def _get_signature(params, secret, timestamp, expiry):
signer = Signer(key=secret)
encoded_params = json.dumps(params, sort_keys=True)
timestamp = str(timestamp)
expiry = str(expiry)
return signer.signature(":".join([timestamp, expiry, encoded_params]))
示例3: dispatch
# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import signature [as 别名]
def dispatch(self, request, *args, **kwargs):
self.object = self.get_object()
signer = Signer()
s1 = signer.signature(self.object.email)
s2 = kwargs.get('sign_user', None)
if self.object.is_active == True:
raise Http404("Account is active yet!")
if s1<>s2:
raise Http404("Invalid confirm email information")
return super(EmailUserConfirmView, self).dispatch(request, *args, **kwargs)
示例4: test_registration_and_confirm_user
# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import signature [as 别名]
def test_registration_and_confirm_user(self):
response = self.client.post('/registration/', {'email':'[email protected]'})
self.assertIn('reference',response.context)
ref = response.context['reference']
signer = Signer()
sign = signer.signature("[email protected]")
self.assertRegexpMatches(ref, sign)
response = self.client.post(ref, {'email':'[email protected]', 'password1':'Coxb2014', 'password2':'Coxb2014'})
log = self.client.login(username='[email protected]', password='Coxb2014')
self.assertTrue(log)
ClearModels()
示例5: get_signature
# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import signature [as 别名]
def get_signature(secret, body, timestamp, url):
if not body:
body = ""
signer = Signer(key=secret)
return signer.signature( ":".join([body, timestamp, url]) )
示例6: _generate_signature
# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import signature [as 别名]
def _generate_signature(params, secret, timestamp):
signer = Signer(key=secret)
encoded_params = json.dumps(params, sort_keys=True)
return signer.signature(":".join([timestamp, encoded_params]))
示例7: get_token
# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import signature [as 别名]
def get_token(email):
signer = Signer()
return signer.signature(email)
示例8: generateHash
# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import signature [as 别名]
def generateHash(self):
signer = Signer(salt=self.user.date_joined.strftime("%Y-%m-%d %H:%i:%s") + str(random.randint(1, 100)))
self.temp_hash = signer.signature(self.user.username)
self.save()
return self.temp_hash
# def getHash(self):
# return self.temp_hash
# def getType(self):
# return self.user_type
# def setType(self, newType):
# TYPES_TO_GROUPS = {
# 'regular': ['Regular', ],
# 'admin': ['Administrators', 'Staff', 'Photographers', 'Journalists', 'Regular'],
# 'staff': ['Staff', 'Photographers', 'Journalists', 'Regular'],
# 'photographer': ['Photographers', 'Regular'],
# 'journalist': ['Journalists', 'Regular'],
# }
#
# self.user_type = newType
#
# if newType == 'admin' or newType == 'staff':
# self.user.is_staff = True
# else:
# self.user.is_staff = False
#
# for groupName in TYPES_TO_GROUPS[newType]:
# group, _ = Group.objects.get_or_create(name=groupName)
# group.user_set.add(self.user)
#
# self.temp_hash = ''
# self.save()
#
# return True
# Create a new user profile
# @staticmethod
# def createUser(username, email, password):
# try:
# user = User.objects.get(username=username)
# signer = Signer(salt=user.date_joined.strftime("%Y-%m-%d %H:%i:%s") + str(random.randint(1, 100)))
# regHash = signer.signature(user.username) # registration confirmation hash
# SiteUser.objects.create(user=user, temp_hash=regHash, saved_new_password=True)
#
# return regHash
# except IntegrityError as e:
# # Duplicate entry
# if e.args[0] == 1062:
# raise CreateUserError(u'Toks vartotojo vardas jau užregistruotas.')
# except Exception as e:
# plainText = get_template('registration_error_email.txt')
# subject = u'Klaida vartotojo registracijos metu'
# c = Context({
# 'username': username,
# 'email_address': email,
# 'error_message': e,
# })
#
# mail_admins(subject, plainText.render(c))
# raise CreateUserError(u'Klaidos priežastis nežinoma. Svetainės administratoriai buvo informuoti apie šią klaidą.')
#class Organizer(models.Model):
# #organizer_id = models.PositiveIntegerField(primary_key = True)
# organization_title = models.CharField(max_length = 40, blank = True)
# first_name = models.CharField(max_length = 30, blank = True)
# last_name = models.CharField(max_length = 30, blank = True)
#
# class Meta:
# db_table = 'organizers'
#
# def __unicode__(self):
# if self.first_name:
# return u'%s %s' % (self.first_name, self.last_name)
# else:
# return self.organization_title
# Data model containing addresses; allows to specify a title for concise references; allows to specify an address type; a Person entity can have multiple addresses;
#class GenericAddress(models.Model):
# #address_id = models.PositiveIntegerField(primary_key = True)
# title = models.CharField(max_length = 20, blank = True) # title of the address (e.g. "Susivienijimas Lietuvių Amerikoje"), used to concisely reference an Address entity
# street_address1 = models.CharField(max_length = 30)
# street_address2 = models.CharField(max_length = 30, blank = True)
# street_address3 = models.CharField(max_length = 30, blank = True)
# street_address4 = models.CharField(max_length = 30, blank = True)
# city = models.CharField(max_length = 20, blank = True)
# zip_code = models.CharField(max_length = 10, blank = True)
# state = USStateField(blank = True, null = True)
# country = models.ForeignKey(Country, blank = True)
# type = models.CharField(max_length = 20, verbose_name='Address type') # e.g. Home address, Work address, Headquarters, etc.
# #entity = models.ForeignKey(Entity) # entity owning this address entry
#
# class Meta:
# abstract = True
#
# def __unicode__(self):
# if self.title:
# return self.title
# else:
#.........这里部分代码省略.........
示例9: test_base_account_methods
# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import signature [as 别名]
def test_base_account_methods(self):
# no user else (401)
fill = {
'email': self.EMAIL,
'password': self.PASS
}
# no user else (401)
self.post(self.login_url, data=fill, status_code=HTTP_401_UNAUTHORIZED)
# invaite user
fill = {
'first_name': self.FIRST_NAME,
'last_name': self.LAST_NAME,
'email': self.EMAIL,
}
# anonymous invaiting
self.post(self.invaite_url, data=fill, status_code=HTTP_403_FORBIDDEN)
# admin invation
User.objects.create_superuser(self.ADMIN_EMAIL, self.ADMIN_PASS)
self._login_adm()
mail_count = len(mail.outbox)
self.post(self.invaite_url, data=fill, status_code=201)
self.assertEqual(len(mail.outbox), mail_count + 1)
# user properties
user = User.objects.get(email=self.EMAIL)
self.assertEqual(user.is_active, False)
self.assertEqual(user.is_admin, False)
self.assertEqual(user.is_staff, False)
self.assertEqual(
user.get_full_name(),
'{} {}'.format(self.FIRST_NAME, self.LAST_NAME)
)
self.assertEqual(user.get_short_name(), self.FIRST_NAME)
self.assertEqual(user.__unicode__(), self.EMAIL)
self.assertEqual(user.has_perm(None), True)
self.assertEqual(user.has_module_perms(None), True)
self.assertEqual(user.username, self.EMAIL)
# confim user
signer = Signer()
sign = signer.signature(self.EMAIL)
fill = {
'pk': user.id,
'token': sign
}
response = self.get(
self.confirm_url, data=fill, status_code=HTTP_200_OK
)
# confim wrong user.id
fill = {
'pk': user.id+10,
'token': sign
}
self.get(self.confirm_url, data=fill, status_code=HTTP_400_BAD_REQUEST)
# confim wrong token
fill = {
'pk': user.id,
'token': sign+'1'
}
self.get(self.confirm_url, data=fill, status_code=HTTP_400_BAD_REQUEST)
# activates user
fill = {
'pk': user.id,
'token': sign,
'first_name': self.FIRST_NAME,
'last_name': self.LAST_NAME,
'email': self.EMAIL,
'password': self.PASS,
'phone': '+7800800800'
}
# activate wrong user.id
fill['pk'] = user.id + 10
self.post(
self.activate_url, data=fill, status_code=HTTP_400_BAD_REQUEST
)
# activate wrong token
fill['pk'] = user.id
fill['token'] = sign+'1'
self.post(
self.activate_url, data=fill, status_code=HTTP_400_BAD_REQUEST
)
# activate and login user
fill['token'] = sign
response = self.post(
self.activate_url, data=fill, status_code=HTTP_200_OK
)
self.assertEqual(response.json['success'], _('User logged in'))
#.........这里部分代码省略.........
示例10: get_token
# 需要导入模块: from django.core.signing import Signer [as 别名]
# 或者: from django.core.signing.Signer import signature [as 别名]
def get_token(self, obj):
if obj.is_active:
return None
signer = Signer()
return signer.signature(obj.email)