Skip to content

Commit

Permalink
Remove iam.knox submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Apr 18, 2024
1 parent 519dec9 commit dc44f70
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 57 deletions.
12 changes: 6 additions & 6 deletions backend/ciso_assistant/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@

# beware of the order of url patterns, this can change de behavior in case of multiple matches and avoid giving identical paths that could cause conflicts
urlpatterns = [
path("api/", include("core.urls")),
path("serdes/", include("serdes.urls")),
path("i18n/", include("django.conf.urls.i18n")),
path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
path("", SpectacularAPIView.as_view(), name="schema"),
path(
"api/schema/swagger/",
"schema/swagger/",
SpectacularSwaggerView.as_view(url_name="schema"),
name="swagger",
),
path(
"api/schema/redoc/",
"schema/redoc/",
SpectacularRedocView.as_view(url_name="schema"),
name="redoc",
),
path("api/", include("core.urls")),
path("serdes/", include("serdes.urls")),
path("i18n/", include("django.conf.urls.i18n")),
]
Empty file removed backend/iam/knox/__init__.py
Empty file.
18 changes: 0 additions & 18 deletions backend/iam/knox/views.py

This file was deleted.

12 changes: 9 additions & 3 deletions backend/iam/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

from core.views import FirstConnexionPasswordConfirmView

from .views import *
from .knox.views import LoginView as KnoxLoginView
from .views import (
LoginView,
ChangePasswordView,
CurrentUserView,
PasswordResetView,
ResetPasswordConfirmView,
SetPasswordView,
)
import knox.views as knox_views

urlpatterns = [
path(r"login/", KnoxLoginView.as_view(), name="knox_login"),
path(r"login/", LoginView.as_view(), name="knox_login"),
path(r"logout/", knox_views.LogoutView.as_view(), name="knox_logout"),
path(r"logoutall/", knox_views.LogoutAllView.as_view(), name="knox_logoutall"),
path("current-user/", CurrentUserView.as_view(), name="current-user"),
Expand Down
41 changes: 11 additions & 30 deletions backend/iam/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
)
from rest_framework.settings import api_settings
from ciso_assistant.settings import EMAIL_HOST, EMAIL_HOST_RESCUE
from rest_framework.authtoken.serializers import AuthTokenSerializer
from knox.views import LoginView as KnoxLoginView

from .serializers import (
ChangePasswordSerializer,
Expand All @@ -31,37 +33,16 @@
User = get_user_model()


class LoginView(views.APIView):
permission_classes = [permissions.AllowAny]
class LoginView(KnoxLoginView):
permission_classes = (permissions.AllowAny,)
serializer_class = LoginSerializer

@method_decorator(ensure_csrf_cookie)
def post(self, request) -> Response:
serializer = LoginSerializer(
data=self.request.data,
context={"request": self.request},
)
try:
serializer.is_valid(raise_exception=True)
user = serializer.validated_data["user"]
login(request, user)
logger.info("login succesful", user=user)
except serializers.ValidationError as e:
logger.warning(
"login attempt failed",
error=e,
username=request.data.get("username"),
)
if isinstance(e.detail, dict):
return Response(data={**e.detail}, status=HTTP_401_UNAUTHORIZED)
else:
return Response(
data={api_settings.NON_FIELD_ERRORS_KEY: [e.detail]},
status=HTTP_401_UNAUTHORIZED,
)

user.first_login = False
user.save()
return Response(None, status=HTTP_202_ACCEPTED)
def post(self, request, format=None):
serializer = AuthTokenSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = serializer.validated_data["user"]
login(request, user)
return super(LoginView, self).post(request, format=None)


class LogoutView(views.APIView):
Expand Down

0 comments on commit dc44f70

Please sign in to comment.