Skip to content

Commit

Permalink
Removed simplejwt related code
Browse files Browse the repository at this point in the history
  • Loading branch information
tonioo committed Apr 19, 2024
1 parent b059a11 commit 61d0157
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions modoboa/core/api/v2/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from rest_framework.authtoken.models import Token
from rest_framework.decorators import action
from rest_framework.exceptions import PermissionDenied
from rest_framework_simplejwt.tokens import RefreshToken

# from rest_framework_simplejwt.tokens import RefreshToken

from modoboa.admin.api.v1 import serializers as admin_v1_serializers
from modoboa.core.api.v1 import serializers as core_v1_serializers
Expand Down Expand Up @@ -79,20 +80,20 @@ def manage_api_token(self, request):
serializer = serializers.UserAPITokenSerializer({"token": str(token)})
return response.Response(serializer.data, status=status)

@action(methods=["post"], detail=False, url_path="tfa/verify")
def tfa_verify_code(self, request):
"""Verify given code validity."""
serializer = serializers.VerifyTFACodeSerializer(
data=request.data, context={"user": request.user}
)
serializer.is_valid(raise_exception=True)
refresh = RefreshToken.for_user(request.user)
refresh[constants.TFA_DEVICE_TOKEN_KEY] = serializer.validated_data[
"code"
].persistent_id
return response.Response(
{"refresh": str(refresh), "access": str(refresh.access_token)}
)
# @action(methods=["post"], detail=False, url_path="tfa/verify")
# def tfa_verify_code(self, request):
# """Verify given code validity."""
# serializer = serializers.VerifyTFACodeSerializer(
# data=request.data, context={"user": request.user}
# )
# serializer.is_valid(raise_exception=True)
# refresh = RefreshToken.for_user(request.user)
# refresh[constants.TFA_DEVICE_TOKEN_KEY] = serializer.validated_data[
# "code"
# ].persistent_id
# return response.Response(
# {"refresh": str(refresh), "access": str(refresh.access_token)}
# )

@action(methods=["get"], detail=False, url_path="tfa/setup/key")
def tfa_setup_get_key(self, request):
Expand Down Expand Up @@ -129,13 +130,13 @@ def tfa_setup_check(self, request):
request.user.save()
# Generate new tokens
device = request.user.totpdevice_set.first()
refresh = RefreshToken.for_user(request.user)
refresh[constants.TFA_DEVICE_TOKEN_KEY] = device.persistent_id
# refresh = RefreshToken.for_user(request.user)
# refresh[constants.TFA_DEVICE_TOKEN_KEY] = device.persistent_id
return response.Response(
{
"tokens": tokens,
"refresh": str(refresh),
"access": str(refresh.access_token),
# "refresh": str(refresh),
# "access": str(refresh.access_token),
}
)

Expand Down

0 comments on commit 61d0157

Please sign in to comment.