我们从Python开源项目中,提取了以下40个代码示例,用于说明如何使用django.utils.http.base36_to_int()。
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
def check_token(self, user, token): # 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) > \ self.timeout: return False return True
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
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
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
def get_project_id(self, token): try: project_b36, digest = token.split("-") project_id = base36_to_int(project_b36) except ValueError: return None return project_id
def get_user(self): try: uid_int = base36_to_int(self.kwargs["uidb36"]) except ValueError: raise Http404() return get_object_or_404(User, id=uid_int)
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)
def password_reset_confirm_uidb36(request, uidb36=None, **kwargs): # Support old password reset URLs that used base36 encoded user IDs. # Remove in Django 1.7 try: uidb64 = force_text(urlsafe_base64_encode(force_bytes(base36_to_int(uidb36)))) except ValueError: uidb64 = '1' # dummy invalid ID (incorrect padding for base64) return password_reset_confirm(request, uidb64=uidb64, **kwargs)
def check_token(self, user, token): """ Check that a connection 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.CONNECTION_LINK_VALIDITY: return False return True
def password_reset_from_key(request, uidb36, key, **kwargs): form_class = kwargs.get("form_class", ResetPasswordKeyForm) template_name = kwargs.get("template_name", "account/password_reset_from_key.html") token_generator = kwargs.get("token_generator", default_token_generator) group, bridge = group_and_bridge(kwargs) ctx = group_context(group, bridge) # pull out user try: uid_int = base36_to_int(uidb36) except ValueError: raise Http404 user = get_object_or_404(User, id=uid_int) if token_generator.check_token(user, key): if request.method == "POST": password_reset_key_form = form_class(request.POST, user=user, temp_key=key) if password_reset_key_form.is_valid(): password_reset_key_form.save() messages.add_message(request, messages.SUCCESS, ugettext(u"Password successfully changed.") ) password_reset_key_form = None else: password_reset_key_form = form_class() ctx.update({ "password": "active", "form": password_reset_key_form, }) else: ctx.update({ "password": "active", "token_fail": True, }) return render_to_response(template_name, RequestContext(request, ctx))
def password_reset_from_key(request, uidb36, key, **kwargs): form_class = kwargs.get("form_class", ResetPasswordKeyForm) template_name = kwargs.get("template_name", "account/password_reset_from_key.html") token_generator = kwargs.get("token_generator", default_token_generator) group, bridge = group_and_bridge(kwargs) ctx = group_context(group, bridge) # pull out user try: uid_int = base36_to_int(uidb36) except ValueError: raise Http404 user = get_object_or_404(User, id=uid_int) if token_generator.check_token(user, key): if request.method == "POST": password_reset_key_form = form_class(request.POST, user=user, temp_key=key) if password_reset_key_form.is_valid(): password_reset_key_form.save() messages.add_message(request, messages.SUCCESS, ugettext(u"Password successfully changed.") ) password_reset_key_form = None else: password_reset_key_form = form_class() ctx.update({ "form": password_reset_key_form, }) else: ctx.update({ "token_fail": True, }) return render_to_response(template_name, RequestContext(request, ctx))