From d314303066392acbfd783e473ecde6808aab7927 Mon Sep 17 00:00:00 2001 From: Timofey Date: Fri, 29 Aug 2025 14:20:50 +0300 Subject: [PATCH] backend router --- backend/api/auth/__init__.py | 0 backend/api/auth/serializers.py | 0 backend/api/auth/urls.py | 6 ++++++ backend/api/auth/views.py | 0 backend/api/urls.py | 5 +++++ backend/api/views.py | 3 --- backend/base/asgi.py | 9 --------- backend/base/settings.py | 29 ++++++++++++++++++++++++++--- backend/base/urls.py | 24 +++++++----------------- backend/base/wsgi.py | 9 --------- 10 files changed, 44 insertions(+), 41 deletions(-) create mode 100644 backend/api/auth/__init__.py create mode 100644 backend/api/auth/serializers.py create mode 100644 backend/api/auth/urls.py create mode 100644 backend/api/auth/views.py create mode 100644 backend/api/urls.py delete mode 100644 backend/api/views.py diff --git a/backend/api/auth/__init__.py b/backend/api/auth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/api/auth/serializers.py b/backend/api/auth/serializers.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/api/auth/urls.py b/backend/api/auth/urls.py new file mode 100644 index 0000000..8cd93a9 --- /dev/null +++ b/backend/api/auth/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +# from . views import () + +urlpatterns = [ + +] \ No newline at end of file diff --git a/backend/api/auth/views.py b/backend/api/auth/views.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/api/urls.py b/backend/api/urls.py new file mode 100644 index 0000000..c194f05 --- /dev/null +++ b/backend/api/urls.py @@ -0,0 +1,5 @@ +from django.urls import path, include + +urlpatterns = [ + path('v1/auth/', include('api.auth.urls')) +] \ No newline at end of file diff --git a/backend/api/views.py b/backend/api/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/backend/api/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/backend/base/asgi.py b/backend/base/asgi.py index 71a4cef..266428d 100644 --- a/backend/base/asgi.py +++ b/backend/base/asgi.py @@ -1,12 +1,3 @@ -""" -ASGI config for base project. - -It exposes the ASGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ -""" - import os from django.core.asgi import get_asgi_application diff --git a/backend/base/settings.py b/backend/base/settings.py index 8618a55..5f03605 100644 --- a/backend/base/settings.py +++ b/backend/base/settings.py @@ -1,6 +1,7 @@ import os from pathlib import Path from dotenv import load_dotenv +from datetime import timedelta BASE_DIR = Path(__file__).resolve().parent.parent load_dotenv(dotenv_path=BASE_DIR / './.env') @@ -33,6 +34,26 @@ CORS_ALLOW_HEADERS = [ 'cookie' ] +REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': [ + 'rest_framework_simplejwt.authentication.JWTAuthentication', + 'rest_framework.authentication.SessionAuthentication', + ], +} + + +SIMPLE_JWT = { + 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=15), + 'REFRESH_TOKEN_LIFETIME': timedelta(days=7), + 'ROTATE_REFRESH_TOKENS': True, + 'BLACKLIST_AFTER_ROTATION': True, + 'UPDATE_LAST_LOGIN': True, + 'ALGORITHM': 'HS256', + 'SIGNING_KEY': SECRET_KEY, + 'VERIFYING_KEY': None, + 'AUTH_HEADER_TYPES': ('Bearer',), + 'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',), +} INSTALLED_APPS = [ 'django.contrib.admin', @@ -48,6 +69,7 @@ INSTALLED_APPS = [ ] MIDDLEWARE = [ + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -104,10 +126,11 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] -LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'UTC' -USE_I18N = True +LANGUAGE_CODE = 'ru-ru' +TIME_ZONE = 'Europe/Minsk' USE_TZ = True +USE_I18N = True +USE_L10N = True STATIC_URL = 'static/' diff --git a/backend/base/urls.py b/backend/base/urls.py index c7a45b4..2d42021 100644 --- a/backend/base/urls.py +++ b/backend/base/urls.py @@ -1,22 +1,12 @@ -""" -URL configuration for base project. - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/5.2/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" from django.contrib import admin -from django.urls import path +from django.urls import path, include +from django.conf import settings +from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls), + path('api/', include('api.urls')), ] + +if settings.DEBUG: + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/backend/base/wsgi.py b/backend/base/wsgi.py index 70ae90a..f846bd0 100644 --- a/backend/base/wsgi.py +++ b/backend/base/wsgi.py @@ -1,12 +1,3 @@ -""" -WSGI config for base project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ -""" - import os from django.core.wsgi import get_wsgi_application