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


Python http.base36_to_int方法代码示例

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


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

示例1: check_token

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def check_token(self, user, token):
        """
        Check that a password reset token is correct for a given user.
        """
        # Parse the token
        try:
            ts_b36, hash = token.split("-")
        except ValueError:
            return False

        try:
            ts = base36_to_int(ts_b36)
        except ValueError:
            return False

        # Check that the timestamp/uid has not been tampered with
        if not constant_time_compare(self._make_token_with_timestamp(user, ts), token):
            return False

        # Check the timestamp is within limit
        if (self._num_days(self._today()) - ts) > settings.PASSWORD_RESET_TIMEOUT_DAYS:
            return False

        return True 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:26,代码来源:tokens.py

示例2: check_token

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def check_token(self, user, token):
        """
        Check that a activation token is correct for a given user.
        """
        # Parse the token
        try:
            ts_b36, hash = token.split('-')
        except ValueError:
            return False

        try:
            ts = base36_to_int(ts_b36)
        except ValueError:
            return False

        # Check that the timestamp/uid has not been tampered with
        if not constant_time_compare(self._make_token_with_timestamp(user, ts), token):
            return False

        # Check the timestamp is within limit
        if (self._num_days(self._today()) - ts) > settings.USERS_EMAIL_CONFIRMATION_TIMEOUT_DAYS:
            return False

        return True 
开发者ID:mishbahr,项目名称:django-users2,代码行数:26,代码来源:utils.py

示例3: url_str_to_user_pk

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def url_str_to_user_pk(s):
    User = get_user_model()
    # TODO: Ugh, isn't there a cleaner way to determine whether or not
    # the PK is a str-like field?
    if getattr(User._meta.pk, 'rel', None):
        pk_field = User._meta.pk.rel.to._meta.pk
    else:
        pk_field = User._meta.pk
    if (hasattr(models, 'UUIDField') and issubclass(
            type(pk_field), models.UUIDField)):
        return s
    try:
        pk_field.to_python('a')
        pk = s
    except ValidationError:
        pk = base36_to_int(s)
    return pk 
开发者ID:django-leonardo,项目名称:django-leonardo,代码行数:19,代码来源:utils.py

示例4: check_token

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def check_token(self, user, token):
        """
        Check that a password reset token is correct for a given user.
        """
        if not (user and token):
            return False
        # Parse the token
        try:
            ts_b36, hash = token.split("-")
        except ValueError:
            return False

        try:
            ts = base36_to_int(ts_b36)
        except ValueError:
            return False

        # Check that the timestamp/uid has not been tampered with
        if not constant_time_compare(self._make_token_with_timestamp(user, ts), token):
            return False

        # Check the timestamp is within limit
        if (self._num_days(self._today()) - ts) > settings.PASSWORD_RESET_TIMEOUT_DAYS:
            return False

        return True 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:28,代码来源:tokens.py

示例5: check_token

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def check_token(self, user, token):
        """
        Check that a password reset token is correct for a given user.
        """
        if not (user and token):
            return False
        # Parse the token
        try:
            ts_b36, hash = token.split("-")
        except ValueError:
            return False

        try:
            ts = base36_to_int(ts_b36)
        except ValueError:
            return False

        # Check that the timestamp/uid has not been tampered with
        if not constant_time_compare(self._make_token_with_timestamp(user, ts), token):
            return False

        # Check the timestamp is within limit. Timestamps are rounded to
        # midnight (server time) providing a resolution of only 1 day. If a
        # link is generated 5 minutes before midnight and used 6 minutes later,
        # that counts as 1 day. Therefore, PASSWORD_RESET_TIMEOUT_DAYS = 1 means
        # "at least 1 day, could be up to 2."
        if (self._num_days(self._today()) - ts) > settings.PASSWORD_RESET_TIMEOUT_DAYS:
            return False

        return True 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:32,代码来源:tokens.py

示例6: from_encoded_id_luhn_base36

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def from_encoded_id_luhn_base36(cls, encoded_id):
        from htk.utils.luhn import is_luhn_valid
        id_with_luhn = base36_to_int(encoded_id)
        if is_luhn_valid(id_with_luhn):
            xored = id_with_luhn // 10
            xor_key = cls._luhn_xor_key()
            obj_id =  xored ^ xor_key
            obj = cls.objects.get(id=obj_id)
        else:
            obj = None
        return obj 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:13,代码来源:classes.py

示例7: decrypt_uid

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def decrypt_uid(encrypted_uid):
    uid_xor = htk_setting('HTK_USER_ID_XOR')
    user_id = base36_to_int(encrypted_uid) ^ uid_xor
    return user_id 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:6,代码来源:general.py

示例8: resolve_cpq_code

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def resolve_cpq_code(cpq_code, cpq_type=CPQType.INVOICE):
    """Returns the CPQ object (Quote or Invoice) for this `cpq_code`
    """
    check_hash = cpq_code[:CPQ_CHECK_HASH_LENGTH]
    cpq_code = cpq_code[CPQ_CHECK_HASH_LENGTH:]
    if is_valid_cpq_code_check_hash(cpq_code, check_hash):
        if cpq_type == CPQType.INVOICE:
            CPQModel = resolve_model_dynamically(settings.HTK_CPQ_INVOICE_MODEL)
        elif cpq_type == CPQType.QUOTE:
            CPQModel = resolve_model_dynamically(settings.HTK_CPQ_QUOTE_MODEL)
        elif cpq_type == CPQType.GROUP_QUOTE:
            CPQModel = resolve_model_dynamically(settings.HTK_CPQ_GROUP_QUOTE_MODEL)
        else:
            raise Exception('Bad value for cpq_type')
        try:
            padded = base36_to_int(cpq_code)
            if is_luhn_valid(padded):
                xored = padded // 10
                cpq_id = xored ^ CPQ_XOR_KEY
                cpq = CPQModel.objects.get(id=cpq_id)
            else:
                cpq = None
        except ValueError:
            cpq = None
        except CPQModel.DoesNotExist:
            cpq = None
    else:
        cpq = None
    return cpq 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:31,代码来源:crypto.py

示例9: get_user

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def get_user(self):
        try:
            uid_int = base36_to_int(self.kwargs["uidb36"])
        except ValueError:
            raise Http404()
        return get_object_or_404(get_user_model(), id=uid_int) 
开发者ID:madre,项目名称:devops,代码行数:8,代码来源:views.py

示例10: password_reset_confirm

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def password_reset_confirm(request, uidb36=None, token=None, template_name='registration/password_reset_confirm.html',
                           token_generator=default_token_generator, set_password_form=SetPasswordForm,
                           post_reset_redirect=None):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    """
    assert uidb36 is not None and token is not None # checked by URLconf
    if post_reset_redirect is None:
        post_reset_redirect = reverse('drawquest.apps.drawquest_auth.views.password_reset_complete')
    try:
        uid_int = base36_to_int(uidb36)
        user = User.objects.get(id=uid_int)
    except (ValueError, User.DoesNotExist):
        user = None

    ctx = {}

    if user is not None and token_generator.check_token(user, token):
        ctx['validlink'] = True
        if request.method == 'POST':
            form = set_password_form(user, request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(post_reset_redirect)
        else:
            form = set_password_form(None)
    else:
        ctx['validlink'] = False
        form = None
    ctx['form'] = form
    return r2r_jinja(template_name, ctx, request) 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:34,代码来源:views.py

示例11: check_token

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def check_token(self, user, token, expire_minutes=-1):
    try:
      (timestamp, content_type_id, object_id, _) = token.split("-")
      timestamp = base36_to_int(timestamp)
      content_type_id = base36_to_int(content_type_id)
      object_id = base36_to_int(object_id)
    except ValueError:
      return None
    if not constant_time_compare(self._make_hash(user, timestamp, content_type_id, object_id), token):
      return None
    if self._num_minutes() - timestamp > expire_minutes > 0:
      return None
    return ContentType.objects.get_for_id(content_type_id).get_object_for_this_type(pk=object_id) 
开发者ID:F0RE1GNERS,项目名称:eoj3,代码行数:15,代码来源:hash.py

示例12: reset_password

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import base36_to_int [as 别名]
def reset_password(
    request,
    data=None,
    redirect_url_name='account_password_reset_success',
    template='account/reset_password.html',
    renderer=_r
):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    Based off of django.contrib.auth.views.password_reset_confirm
    Need to customize error display
    """
    if data is None:
        data = wrap_data(request)

    uidb36 = request.GET.get('u', None)
    token = request.GET.get('t', None)
    token_generator = default_token_generator
    success = False
    response = None
    if uidb36 and token:
        UserModel = get_user_model()
        try:
            uid_int = base36_to_int(uidb36)
            user = UserModel.objects.get(id=uid_int)
        except (ValueError, UserModel.DoesNotExist):
            user = None

        if user is not None and token_generator.check_token(user, token):
            validlink = True
            if request.method == 'POST':
                form = UpdatePasswordForm(user, request.POST)
                if form.is_valid():
                    user = form.save()
                    if htk_setting('HTK_ACCOUNTS_CHANGE_PASSWORD_UPDATE_SESSION_AUTH_HASH'):
                        from django.contrib.auth import update_session_auth_hash
                        update_session_auth_hash(request, user)
                    success = True
            else:
                form = UpdatePasswordForm(None)
            if 'input_attrs' in data:
                set_input_attrs(form, attrs=data['input_attrs'])
        else:
            validlink = False
            form = None
        data['form'] = form
        data['validlink'] = validlink
    else:
        data['validlink'] = False
    if success:
        response = redirect(reverse(redirect_url_name))
    else:
        response = renderer(request, template, data=data)
    return response 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:57,代码来源:views.py


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