stages/email: slugify token identifier

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-09-20 19:26:25 +02:00
parent f463296d47
commit 3195640776
1 changed files with 3 additions and 2 deletions

View File

@ -5,6 +5,7 @@ from django.contrib import messages
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.urls import reverse from django.urls import reverse
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils.text import slugify
from django.utils.timezone import now from django.utils.timezone import now
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from rest_framework.fields import CharField from rest_framework.fields import CharField
@ -64,7 +65,7 @@ class EmailStageView(ChallengeStageView):
) # + 1 because django timesince always rounds down ) # + 1 because django timesince always rounds down
token_filters = { token_filters = {
"user": pending_user, "user": pending_user,
"identifier": f"ak-email-stage-{current_stage.name}-{pending_user}", "identifier": slugify(f"ak-email-stage-{current_stage.name}-{pending_user}"),
} }
# Don't check for validity here, we only care if the token exists # Don't check for validity here, we only care if the token exists
tokens = Token.objects.filter(**token_filters) tokens = Token.objects.filter(**token_filters)
@ -120,7 +121,7 @@ class EmailStageView(ChallengeStageView):
challenge = EmailChallenge( challenge = EmailChallenge(
data={ data={
"type": ChallengeTypes.NATIVE.value, "type": ChallengeTypes.NATIVE.value,
"title": "Email sent.", "title": _("Email sent."),
} }
) )
return challenge return challenge