Fakultas Ilmu Komputer UI

Commit 220a4c5e authored by Jonathan Christopher Jakub's avatar Jonathan Christopher Jakub
Browse files

[GREEN] Add lowercasing on username on obtain auth token

parent 64040ec0
Pipeline #47732 passed with stages
in 3 minutes and 45 seconds
from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.authtoken.models import Token
from rest_framework.response import Response
from rest_framework import status
class CustomAuthToken(ObtainAuthToken):
def post(self, request, *args, **kwargs):
request_data = request.data
request_data["username"] = request_data["username"].lower()
serializer = self.serializer_class(
context={"request": request}
user = serializer.validated_data["user"]
token, _ = Token.objects.get_or_create(user=user)
return Response(data={ "token": token.key }, status=status.HTTP_200_OK)
from django.contrib import admin
from django.urls import path, include
from rest_framework.authtoken.views import obtain_auth_token
from apps.custom_auth.views import CustomAuthToken
urlpatterns = [
path("admin/", admin.site.urls),
path("accounts/", include("apps.accounts.urls")),
path("cases/", include("apps.cases.urls")),
path("logs/", include("apps.logs.urls")),
path("auth/token/", obtain_auth_token, name="api_token_auth"),
path("auth/token/", CustomAuthToken.as_view(), name="api_token_auth"),
path("auth/", include("django.contrib.auth.urls")),
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment