Skip to content

Commit

Permalink
Encrypt token in start_poll
Browse files Browse the repository at this point in the history
  • Loading branch information
juuso-j committed Mar 15, 2024
1 parent 8cc3495 commit bae4b12
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions profiles/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
SubQuestion,
SubQuestionCondition,
)
from profiles.utils import generate_password, get_user_result
from profiles.utils import encrypt_text, generate_password, get_user_result

from .utils import PostalCodeResultFilter

Expand Down Expand Up @@ -187,7 +187,6 @@ def list(self, request, *args, **kwargs):
permission_classes=[AllowAny],
)
def start_poll(self, request):
# TODO check recaptha
uuid4 = uuid.uuid4()
username = f"anonymous_{str(uuid4)}"
user = User.objects.create(pk=uuid4, username=username, is_generated=True)
Expand All @@ -196,7 +195,8 @@ def start_poll(self, request):
user.profile = Profile.objects.create(user=user)
user.save()
token, _ = Token.objects.get_or_create(user=user)
response_data = {"token": token.key, "id": user.id}
data = encrypt_text(token.key, settings.TOKEN_SECRET)
response_data = {"data": data, "id": user.id}
return Response(response_data, status=status.HTTP_200_OK)

@extend_schema(
Expand Down

0 comments on commit bae4b12

Please sign in to comment.