Python django.utils.http.int_to_base36() Examples
The following are 17
code examples of django.utils.http.int_to_base36().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.utils.http
, or try the search function
.
Example #1
Source File: tokens.py From bioforum with MIT License | 6 votes |
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)
Example #2
Source File: views.py From devops with MIT License | 6 votes |
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)
Example #3
Source File: tokens.py From python2017 with MIT License | 6 votes |
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)
Example #4
Source File: emails.py From django-htk with MIT License | 6 votes |
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 )
Example #5
Source File: tokens.py From openhgsenti with Apache License 2.0 | 6 votes |
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)
Example #6
Source File: tokens.py From fomalhaut-panel with MIT License | 6 votes |
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)
Example #7
Source File: tokens.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
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)
Example #8
Source File: utils.py From django-leonardo with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #9
Source File: tokens.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
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)
Example #10
Source File: classes.py From django-htk with MIT License | 5 votes |
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
Example #11
Source File: general.py From django-htk with MIT License | 5 votes |
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
Example #12
Source File: crypto.py From django-htk with MIT License | 5 votes |
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
Example #13
Source File: update.py From c3nav with Apache License 2.0 | 5 votes |
def build_cache_key(pk, timestamp): return int_to_base36(pk)+'_'+int_to_base36(timestamp)
Example #14
Source File: changeset.py From c3nav with Apache License 2.0 | 5 votes |
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()))
Example #15
Source File: changeset.py From c3nav with Apache License 2.0 | 5 votes |
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()))
Example #16
Source File: utils.py From django-users2 with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #17
Source File: hash.py From eoj3 with MIT License | 5 votes |
def _make_hash(self, user, timestamp, content_type_id, object_id): content = "%s-%s-%s" % (int_to_base36(timestamp), int_to_base36(content_type_id), int_to_base36(object_id)) Hash = salted_hmac( settings.SECRET_KEY[::2], content + six.text_type(user.pk) + user.password ).hexdigest()[::2] return "%s-%s" % (content, Hash)