本文整理匯總了Python中django.utils.http.int_to_base36方法的典型用法代碼示例。如果您正苦於以下問題:Python http.int_to_base36方法的具體用法?Python http.int_to_base36怎麽用?Python http.int_to_base36使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.utils.http
的用法示例。
在下文中一共展示了http.int_to_base36方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _make_token_with_timestamp
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def _make_token_with_timestamp(self, user, timestamp):
# timestamp is number of days since 2001-1-1. Converted to
# base 36, this gives us a 3 digit string until about 2121
ts_b36 = int_to_base36(timestamp)
# By hashing on the internal state of the user and using state
# that is sure to change (the password salt will change as soon as
# the password is set, at least for current Django auth, and
# last_login will also change), we produce a hash that will be
# invalid as soon as it is used.
# We limit the hash to 20 chars to keep URL short
key_salt = "django.contrib.auth.tokens.PasswordResetTokenGenerator"
# Ensure results are consistent across DB backends
login_timestamp = '' if user.last_login is None else user.last_login.replace(microsecond=0, tzinfo=None)
value = (six.text_type(user.pk) + user.password +
six.text_type(login_timestamp) + six.text_type(timestamp))
hash = salted_hmac(key_salt, value).hexdigest()[::2]
return "%s-%s" % (ts_b36, hash)
示例2: _make_token_with_timestamp
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def _make_token_with_timestamp(self, user, timestamp):
# timestamp is number of days since 2001-1-1. Converted to
# base 36, this gives us a 3 digit string until about 2121
ts_b36 = int_to_base36(timestamp)
# By hashing on the internal state of the user and using state
# that is sure to change (the password salt will change as soon as
# the password is set, at least for current Django auth, and
# last_login will also change), we produce a hash that will be
# invalid as soon as it is used.
# We limit the hash to 20 chars to keep URL short
hash = salted_hmac(
self.key_salt,
self._make_hash_value(user, timestamp),
secret=self.secret,
).hexdigest()[::2]
return "%s-%s" % (ts_b36, hash)
示例3: _make_token_with_timestamp
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def _make_token_with_timestamp(self, user, timestamp):
# timestamp is number of days since 2001-1-1. Converted to
# base 36, this gives us a 3 digit string until about 2121
ts_b36 = int_to_base36(timestamp)
# By hashing on the internal state of the user and using state
# that is sure to change (the password salt will change as soon as
# the password is set, at least for current Django auth, and
# last_login will also change), we produce a hash that will be
# invalid as soon as it is used.
# We limit the hash to 20 chars to keep URL short
key_salt = "django.contrib.auth.tokens.PasswordResetTokenGenerator"
# Ensure results are consistent across DB backends
if user.date_updated:
login_timestamp = user.date_updated.replace(microsecond=0, tzinfo=None)
elif user.last_login:
login_timestamp = user.last_login.replace(microsecond=0, tzinfo=None)
else:
login_timestamp = user.date_joined.replace(microsecond=0, tzinfo=None)
value = (six.text_type(user.pk) + user.password +
six.text_type(login_timestamp) + six.text_type(timestamp))
hash = salted_hmac(key_salt, value).hexdigest()[::2]
return "%s-%s" % (ts_b36, hash)
示例4: _make_token_with_timestamp
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def _make_token_with_timestamp(self, user, timestamp):
# timestamp is number of days since 2001-1-1. Converted to
# base 36, this gives us a 3 digit string until about 2121
ts_b36 = int_to_base36(timestamp)
# By hashing on the internal state of the user and using state
# that is sure to change (the password salt will change as soon as
# the password is set, at least for current Django auth, and
# last_login will also change), we produce a hash that will be
# invalid as soon as it is used.
# We limit the hash to 20 chars to keep URL short
hash = salted_hmac(
self.key_salt,
self._make_hash_value(user, timestamp),
).hexdigest()[::2]
return "%s-%s" % (ts_b36, hash)
示例5: password_reset_email
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def password_reset_email(user, token_generator, use_https=False, domain=None, template=None, subject=None, sender=None):
domain = domain or htk_setting('HTK_DEFAULT_DOMAIN')
context = {
'user': user,
'email': user.profile.confirmed_email or user.email,
'protocol': use_https and 'https' or 'http',
'domain': domain,
'site_name': htk_setting('HTK_SITE_NAME'),
'reset_path': reverse(htk_setting('HTK_ACCOUNTS_RESET_PASSWORD_URL_NAME')),
'uid': int_to_base36(user.id),
'token': token_generator.make_token(user),
}
reset_uri = '%(protocol)s://%(domain)s%(reset_path)s?u=%(uid)s&t=%(token)s' % context
context['reset_uri'] = reset_uri
template = template or 'accounts/reset_password'
subject = (subject or htk_setting('HTK_ACCOUNT_EMAIL_SUBJECT_PASSWORD_RESET')) % context
send_email(
template=template,
subject=subject,
sender=sender,
to=[context['email']],
context=context
)
示例6: send_email
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def send_email(self, email):
User = get_user_model()
protocol = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http")
current_site = get_current_site(self.request)
email_qs = User.objects.filter(email__iexact=email)
for user in User.objects.filter(pk__in=email_qs.values("user")):
uid = int_to_base36(user.id)
token = self.make_token(user)
password_reset_url = "{0}://{1}{2}".format(
protocol,
current_site.domain,
reverse("account_password_reset_token", kwargs=dict(uidb36=uid, token=token))
)
ctx = {
"user": user,
"current_site": current_site,
"password_reset_url": password_reset_url,
}
hookset.send_password_reset_email([user.email], ctx)
示例7: _make_token_with_timestamp
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def _make_token_with_timestamp(self, user, timestamp):
ts_b36 = int_to_base36(timestamp)
key_salt = 'users.utils.EmailActivationTokenGenerator'
login_timestamp = '' if user.last_login is None else \
user.last_login.replace(microsecond=0, tzinfo=None)
value = (six.text_type(user.pk) + six.text_type(user.email) +
six.text_type(login_timestamp) + six.text_type(timestamp))
hash = salted_hmac(key_salt, value).hexdigest()[::2]
return '%s-%s' % (ts_b36, hash)
示例8: _make_token_with_timestamp
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def _make_token_with_timestamp(self, user, timestamp):
# timestamp is number of days since 2001-1-1. Converted to
# base 36, this gives us a 3 digit string until about 2121
ts_b36 = int_to_base36(timestamp)
hash = salted_hmac(
self.key_salt,
self._make_hash_value(user, timestamp),
secret=self.secret,
).hexdigest()[::2] # Limit to 20 characters to shorten the URL.
return "%s-%s" % (ts_b36, hash)
示例9: user_pk_to_url_str
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def user_pk_to_url_str(user):
"""
This should return a string.
"""
User = get_user_model()
if (hasattr(models, 'UUIDField') and issubclass(
type(User._meta.pk), models.UUIDField)):
if isinstance(user.pk, six.string_types):
return user.pk
return user.pk.hex
ret = user.pk
if isinstance(ret, six.integer_types):
ret = int_to_base36(user.pk)
return str(ret)
示例10: id_with_luhn_base36
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def id_with_luhn_base36(self):
from htk.utils.luhn import calculate_luhn
xor_key = self.__class__._luhn_xor_key()
xored = self.id ^ xor_key
check_digit = calculate_luhn(xored)
id_with_luhn = xored * 10 + check_digit
encoded_id = int_to_base36(id_with_luhn)
return encoded_id
示例11: encrypt_uid
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def encrypt_uid(user):
"""Encrypts the User id for plain
"""
uid_xor = htk_setting('HTK_USER_ID_XOR')
crypt_uid = int_to_base36(user.id ^ uid_xor)
return crypt_uid
示例12: compute_cpq_code
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def compute_cpq_code(cpq):
"""Computes the encoded id for a CPQ object (Quote or Invoice)
"""
xored = cpq.id ^ CPQ_XOR_KEY
check_digit = calculate_luhn(xored)
padded = int(str(xored) + str(check_digit))
cpq_code = int_to_base36(padded)
check_hash = compute_cpq_code_check_hash(cpq_code)
cpq_code = check_hash + cpq_code
return cpq_code
示例13: build_cache_key
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def build_cache_key(pk, timestamp):
return int_to_base36(pk)+'_'+int_to_base36(timestamp)
示例14: last_update_cache_key
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def last_update_cache_key(self):
last_update = self.created if self.last_update_id is None else self.last_update.datetime
return int_to_base36(self.last_update_id or 0)+'_'+int_to_base36(int(make_naive(last_update).timestamp()))
示例15: last_change_cache_key
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import int_to_base36 [as 別名]
def last_change_cache_key(self):
last_change = self.created if self.last_change_id is None else self.last_change.datetime
return int_to_base36(self.last_change_id or 0)+'_'+int_to_base36(int(make_naive(last_change).timestamp()))