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