Initial commit
This commit is contained in:
0
backend/custom_auth/__init__.py
Normal file
0
backend/custom_auth/__init__.py
Normal file
3
backend/custom_auth/admin.py
Normal file
3
backend/custom_auth/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
backend/custom_auth/apps.py
Normal file
6
backend/custom_auth/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AuthConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "custom_auth"
|
||||
0
backend/custom_auth/migrations/__init__.py
Normal file
0
backend/custom_auth/migrations/__init__.py
Normal file
3
backend/custom_auth/models.py
Normal file
3
backend/custom_auth/models.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
3
backend/custom_auth/tests.py
Normal file
3
backend/custom_auth/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
7
backend/custom_auth/urls.py
Normal file
7
backend/custom_auth/urls.py
Normal file
@ -0,0 +1,7 @@
|
||||
from django.urls import path, include
|
||||
from custom_auth import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', include('rest_framework.urls')),
|
||||
path('token/', views.CustomAuthToken.as_view())
|
||||
]
|
||||
17
backend/custom_auth/views.py
Normal file
17
backend/custom_auth/views.py
Normal file
@ -0,0 +1,17 @@
|
||||
from rest_framework.authtoken.views import ObtainAuthToken
|
||||
from rest_framework.authtoken.models import Token
|
||||
from rest_framework.response import Response
|
||||
|
||||
class CustomAuthToken(ObtainAuthToken):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
serializer = self.serializer_class(data=request.data,
|
||||
context={'request': request})
|
||||
serializer.is_valid(raise_exception=True)
|
||||
user = serializer.validated_data['user']
|
||||
token, created = Token.objects.get_or_create(user=user)
|
||||
return Response({
|
||||
'token': token.key,
|
||||
'user_id': user.pk,
|
||||
'email': user.email
|
||||
})
|
||||
Reference in New Issue
Block a user