|
|
|
@ -4,10 +4,12 @@ import time
|
|
|
|
|
|
|
|
|
|
from django.utils.translation import gettext_lazy as _ |
|
|
|
|
from rest_framework import status |
|
|
|
|
from rest_framework.generics import RetrieveAPIView, CreateAPIView |
|
|
|
|
from rest_framework.decorators import action |
|
|
|
|
from rest_framework.generics import RetrieveAPIView |
|
|
|
|
from rest_framework.response import Response |
|
|
|
|
|
|
|
|
|
from authentication.permissions import UserConfirmation |
|
|
|
|
from common.api import JMSGenericViewSet |
|
|
|
|
from common.permissions import IsValidUser |
|
|
|
|
from ..const import ConfirmType |
|
|
|
|
from ..serializers import ConfirmSerializer |
|
|
|
@ -20,10 +22,17 @@ class ConfirmBindORUNBindOAuth(RetrieveAPIView):
|
|
|
|
|
return Response('ok') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ConfirmApi(RetrieveAPIView, CreateAPIView): |
|
|
|
|
class UserConfirmationViewSet(JMSGenericViewSet): |
|
|
|
|
permission_classes = (IsValidUser,) |
|
|
|
|
serializer_class = ConfirmSerializer |
|
|
|
|
|
|
|
|
|
@action(methods=['get'], detail=False) |
|
|
|
|
def check(self, request): |
|
|
|
|
confirm_type = request.query_params.get('confirm_type', 'password') |
|
|
|
|
permission = UserConfirmation.require(confirm_type)() |
|
|
|
|
permission.has_permission(request, self) |
|
|
|
|
return Response('ok') |
|
|
|
|
|
|
|
|
|
def get_confirm_backend(self, confirm_type): |
|
|
|
|
backend_classes = ConfirmType.get_prop_backends(confirm_type) |
|
|
|
|
if not backend_classes: |
|
|
|
@ -34,12 +43,12 @@ class ConfirmApi(RetrieveAPIView, CreateAPIView):
|
|
|
|
|
continue |
|
|
|
|
return backend |
|
|
|
|
|
|
|
|
|
def retrieve(self, request, *args, **kwargs): |
|
|
|
|
def list(self, request, *args, **kwargs): |
|
|
|
|
confirm_type = request.query_params.get('confirm_type', 'password') |
|
|
|
|
backend = self.get_confirm_backend(confirm_type) |
|
|
|
|
if backend is None: |
|
|
|
|
msg = _('This action require verify your MFA') |
|
|
|
|
return Response(data={'error': msg}, status=status.HTTP_404_NOT_FOUND) |
|
|
|
|
return Response(data={'error': msg}, status=status.HTTP_400_BAD_REQUEST) |
|
|
|
|
|
|
|
|
|
data = { |
|
|
|
|
'confirm_type': backend.name, |
|
|
|
|