Quellcode durchsuchen

Returns the user ID and token after requesting an authentication token through the API

TonyKurts vor 1 Jahr
Ursprung
Commit
a87d817564

+ 0 - 0
SharixAdmin/api/__init__.py


+ 1 - 0
SharixAdmin/api/serializers/__init__.py

@@ -0,0 +1 @@
+from SharixAdmin.api.serializers.custom_token import CustomTokenSerializer

+ 9 - 0
SharixAdmin/api/serializers/custom_token.py

@@ -0,0 +1,9 @@
+from rest_framework import serializers
+
+
+class CustomTokenSerializer(serializers.Serializer):
+    user_id = serializers.IntegerField(source='user.pk')
+    auth_token = serializers.CharField(source="key")
+
+    class Meta:
+        fields = ("user_id", "auth_token")

+ 0 - 0
SharixAdmin/api/views/__init__.py


+ 6 - 8
SharixAdmin/urls.py

@@ -4,8 +4,8 @@ from .apiviews import *
 from rest_framework import routers
 from django_spaghetti.views import Plate
 from schema_graph.views import Schema
+from django.conf import settings
 from django.contrib.auth.decorators import login_required
-from core.config import DEBUG
 
 router = routers.SimpleRouter()
 router.register(r'sharix-users', SharixUserMVS)
@@ -47,20 +47,18 @@ urlpatterns = [
     
     path('partner_information/add/', login_required(PartnerInformationCreate.as_view()), name='partner_information/add/'),
     path('partner_information/edit/<int:pk>', login_required(PartnerInformationUpdateView.as_view()), name='partner_information/edit/'),
-    #path('v1/auth/', include('djoser.urls'), name='auth-reg'),
 
     path('user_information', login_required(UserListView.as_view()), name='user_information'),
 
-    #path('v1/auth/', include('djoser.urls')),
-    path('auth/', include('djoser.urls.authtoken'), name='auth'),
-    path('platform/api/', include(router.urls), name="sharix-api"),
+    path('api/v1/auth/', include('djoser.urls.authtoken'), name="api-auth"),
+    path('api/v1/platform/', include(router.urls), name="api-platform"),
+
     path('senderphone/', PhoneSender.as_view()),
+
     #schemas
     path('schemav1/', login_required(Schema.as_view()), name='schemav1'),
     path('schemav2/', login_required(Plate.as_view()),  name='schemav2'),
     path('schemav3/', schema_v3, name='schema'),
     
     re_path(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
-]
-if DEBUG:
-    urlpatterns += path('v1/auth/', include('djoser.urls')),
+]