Skip to content
Snippets Groups Projects
Commit 4ffd465f authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[accounts][models] make temporary url hash unique

parent 7fba594c
No related branches found
No related tags found
1 merge request!328Improve automatic emails with temporary urls
Pipeline #39876 passed
......@@ -160,15 +160,23 @@ def save_user_profile(sender, instance, **kwargs):
instance.profile.save()
def generate_url_hash():
# url_hash creation
url_hash = "".join(
random.choice(string.ascii_letters + string.digits) # nosec
for _ in range(TEMPORARY_URL_LENGTH)
)
return url_hash
class TemporaryUrlManager(models.Manager):
def create_temporary_url(self, status, supervision_track):
# Actions that result creating the object
# url_hash creation
url_hash = "".join(
random.choice(string.ascii_letters + string.digits) # nosec
for _ in range(TEMPORARY_URL_LENGTH)
)
url_hash = generate_url_hash()
used_hashes = [x.url_hash for x in TemporaryUrl.objects.all()]
while url_hash in used_hashes:
url_hash = generate_url_hash()
now = datetime.datetime.now()
expiration_date_delta = datetime.timedelta(
days=settings.ACCOUNT_ACTIVATION_DAYS_FROM_SUPERVISOR
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment