feat: token based auth

This commit is contained in:
Tahinli 2024-06-30 17:36:29 +03:00
parent ef4ca9ab6a
commit 82add23844
7 changed files with 27 additions and 12 deletions

11
.idea/workspace.xml generated
View file

@ -4,14 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="b4bf3f98-d5b7-4d99-9ccf-5a322ed50222" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.vscode/settings.json" beforeDir="false" afterPath="$PROJECT_DIR$/.vscode/settings.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/db.sqlite3" beforeDir="false" afterPath="$PROJECT_DIR$/db.sqlite3" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tJango/settings.py" beforeDir="false" afterPath="$PROJECT_DIR$/tJango/settings.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tJango/urls.py" beforeDir="false" afterPath="$PROJECT_DIR$/tJango/urls.py" afterDir="false" />
</list>
<list default="true" id="b4bf3f98-d5b7-4d99-9ccf-5a322ed50222" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -100,7 +93,7 @@
<updated>1719511805110</updated>
<workItem from="1719511812328" duration="309000" />
<workItem from="1719512143097" duration="830000" />
<workItem from="1719617813873" duration="422000" />
<workItem from="1719617813873" duration="1051000" />
</task>
<servers />
</component>

View file

@ -3,6 +3,7 @@
"python.analysis.indexing": true,
"python.analysis.packageIndexDepths":[["rest_framework", 5, true]],
"cSpell.words": [
"authtoken",
"viewsets"
]
}

Binary file not shown.

View file

@ -38,13 +38,14 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'hello',
'user',
]
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
]
}

View file

@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2024-06-29 23:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('user', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='user',
name='username',
field=models.CharField(max_length=15, unique=True),
),
]

View file

@ -1,5 +1,6 @@
from django.shortcuts import render
from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.decorators import action
from .models import User
from .serializers import UserSerializer
@ -10,7 +11,8 @@ from .serializers import UserSerializer
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = [IsAuthenticatedOrReadOnly]
@action(detail=True, methods=['get'])
@action(detail=False, methods=['get'])
def print_this(self, request, pk=None):
print(self.get_object())