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


Python http.int_to_base36方法代码示例

本文整理汇总了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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:tokens.py

示例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) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:20,代码来源:tokens.py

示例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) 
开发者ID:restran,项目名称:fomalhaut-panel,代码行数:27,代码来源:tokens.py

示例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) 
开发者ID:drexly,项目名称:openhgsenti,代码行数:19,代码来源:tokens.py

示例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
    ) 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:26,代码来源:emails.py

示例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) 
开发者ID:madre,项目名称:devops,代码行数:21,代码来源:views.py

示例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) 
开发者ID:mishbahr,项目名称:django-users2,代码行数:12,代码来源:utils.py

示例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) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:12,代码来源:tokens.py

示例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) 
开发者ID:django-leonardo,项目名称:django-leonardo,代码行数:17,代码来源:utils.py

示例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 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:10,代码来源:classes.py

示例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 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:8,代码来源:general.py

示例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 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:12,代码来源:crypto.py

示例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) 
开发者ID:c3nav,项目名称:c3nav,代码行数:4,代码来源:update.py

示例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())) 
开发者ID:c3nav,项目名称:c3nav,代码行数:5,代码来源:changeset.py

示例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())) 
开发者ID:c3nav,项目名称:c3nav,代码行数:5,代码来源:changeset.py


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