This commit is contained in:
Swydk 2024-08-31 12:10:39 +05:00
parent 456b5cdf3c
commit f079d90d0e
10 changed files with 44 additions and 12 deletions

View File

@ -42,6 +42,7 @@ INSTALLED_APPS = [
'tapdata', 'tapdata',
'stacking', 'stacking',
'rest_framework', 'rest_framework',
'rest_framework_simplejwt',
'corsheaders', '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 = [ 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 = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.postgresql', 'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydatabase', 'NAME': 'erkesh_mal',
'USER': 'myuser', 'USER': 'postgres',
'PASSWORD': 'mypassword', 'PASSWORD': 'swydk',
'HOST': 'db', 'HOST': 'localhost',
'PORT': '5432', 'PORT': '5432',
} }
} }

Binary file not shown.

10
main/permissions.py Normal file
View File

@ -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

View File

@ -4,7 +4,7 @@ from rest_framework.routers import DefaultRouter
from users.views import UserViewSet, DailyRewardViewSet, DailyRewardsListViewSet, BalanceViewSet, LevelsViewSet from users.views import UserViewSet, DailyRewardViewSet, DailyRewardsListViewSet, BalanceViewSet, LevelsViewSet
from tapdata.views import FarmingViewSet from tapdata.views import FarmingViewSet
from stacking.views import UserStakeViewSet, StakeViewSet from stacking.views import UserStakeViewSet, StakeViewSet
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
""" from tapdata.views import TapDataViewSet """ from tapdata.views import TapDataViewSet
from stacking.views import UserStakeViewSet, StakeViewSet """ from stacking.views import UserStakeViewSet, StakeViewSet """
@ -28,4 +28,6 @@ router.register(r'stake', StakeViewSet)
urlpatterns = [ urlpatterns = [
path('api/', include(router.urls)), 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'),
] ]

View File

@ -1,3 +1,3 @@
from django.shortcuts import render from django.shortcuts import render
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
# Create your views here. # Create your views here.