diff --git a/backend/__pycache__/settings.cpython-310.pyc b/backend/__pycache__/settings.cpython-310.pyc index 9c26f27..28cb222 100644 Binary files a/backend/__pycache__/settings.cpython-310.pyc and b/backend/__pycache__/settings.cpython-310.pyc differ diff --git a/backend/settings.py b/backend/settings.py index e53d5ea..2380cfe 100644 --- a/backend/settings.py +++ b/backend/settings.py @@ -42,6 +42,7 @@ INSTALLED_APPS = [ 'tapdata', 'stacking', 'rest_framework', + 'rest_framework_simplejwt', 'corsheaders', ] @@ -57,14 +58,33 @@ MIDDLEWARE = [ ] -REST_FRAMEWORK = { - 'DEFAULT_PERMISSION_CLASSES':[ - 'rest_framework.permissions.AllowAny' - ] -} + +REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': [ + 'rest_framework_simplejwt.authentication.JWTAuthentication', + ], +} +from datetime import timedelta +SIMPLE_JWT = { + 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5), + 'REFRESH_TOKEN_LIFETIME': timedelta(days=1), + 'ROTATE_REFRESH_TOKENS': True, + 'BLACKLIST_AFTER_ROTATION': True, + 'ALGORITHM': 'HS256', + 'SIGNING_KEY': SECRET_KEY, + 'VERIFYING_KEY': None, + 'AUTH_HEADER_TYPES': ('Bearer',), + 'USER_ID_FIELD': 'id', + 'USER_ID_CLAIM': 'user_id', + 'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',), +} CORS_ALLOWED_ORIGINS = [ - 'https://pizzafresca.ru', #TODOPROJECT CHANGE IT + 'https://pizzafresca.ru', + 'http://localhost:3000', + + 'http://localhost:5173', + #TODOPROJECT CHANGE IT # другие источники, если необходимо ] @@ -108,10 +128,10 @@ import os DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'mydatabase', - 'USER': 'myuser', - 'PASSWORD': 'mypassword', - 'HOST': 'db', + 'NAME': 'erkesh_mal', + 'USER': 'postgres', + 'PASSWORD': 'swydk', + 'HOST': 'localhost', 'PORT': '5432', } } diff --git a/main/__pycache__/permissions.cpython-310.pyc b/main/__pycache__/permissions.cpython-310.pyc new file mode 100644 index 0000000..a4986dd Binary files /dev/null and b/main/__pycache__/permissions.cpython-310.pyc differ diff --git a/main/__pycache__/urls.cpython-310.pyc b/main/__pycache__/urls.cpython-310.pyc index 07999e2..bc2d887 100644 Binary files a/main/__pycache__/urls.cpython-310.pyc and b/main/__pycache__/urls.cpython-310.pyc differ diff --git a/main/permissions.py b/main/permissions.py new file mode 100644 index 0000000..7b63638 --- /dev/null +++ b/main/permissions.py @@ -0,0 +1,10 @@ + +from rest_framework.permissions import BasePermission + +class IsAdminUser(BasePermission): + """ + Разрешение, которое позволяет доступ только для администраторов. + """ + + def has_permission(self, request, view): + return request.user and request.user.is_staff \ No newline at end of file diff --git a/main/urls.py b/main/urls.py index 470b3f6..a8d8030 100644 --- a/main/urls.py +++ b/main/urls.py @@ -4,7 +4,7 @@ from rest_framework.routers import DefaultRouter from users.views import UserViewSet, DailyRewardViewSet, DailyRewardsListViewSet, BalanceViewSet, LevelsViewSet from tapdata.views import FarmingViewSet from stacking.views import UserStakeViewSet, StakeViewSet - +from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView """ from tapdata.views import TapDataViewSet from stacking.views import UserStakeViewSet, StakeViewSet """ @@ -28,4 +28,6 @@ router.register(r'stake', StakeViewSet) urlpatterns = [ path('api/', include(router.urls)), + path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'), + path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), ] diff --git a/main/views.py b/main/views.py index 91ea44a..72135be 100644 --- a/main/views.py +++ b/main/views.py @@ -1,3 +1,3 @@ from django.shortcuts import render - +from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView # Create your views here. diff --git a/stacking/__pycache__/serializers.cpython-310.pyc b/stacking/__pycache__/serializers.cpython-310.pyc index 58060f5..17e7df9 100644 Binary files a/stacking/__pycache__/serializers.cpython-310.pyc and b/stacking/__pycache__/serializers.cpython-310.pyc differ diff --git a/stacking/__pycache__/views.cpython-310.pyc b/stacking/__pycache__/views.cpython-310.pyc index ee604dc..102bcee 100644 Binary files a/stacking/__pycache__/views.cpython-310.pyc and b/stacking/__pycache__/views.cpython-310.pyc differ diff --git a/users/__pycache__/views.cpython-310.pyc b/users/__pycache__/views.cpython-310.pyc index 71bec3b..fce195e 100644 Binary files a/users/__pycache__/views.cpython-310.pyc and b/users/__pycache__/views.cpython-310.pyc differ