206 lines
5.8 KiB
Python
206 lines
5.8 KiB
Python
from pathlib import Path
|
|
import os
|
|
from pathlib import Path
|
|
from datetime import timedelta
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
SECRET_KEY =os.getenv("SECRET_KEY")
|
|
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'daphne',
|
|
'django.contrib.staticfiles',
|
|
'corsheaders',
|
|
'rest_framework',
|
|
'rest_framework_simplejwt.token_blacklist',
|
|
'django_extensions',
|
|
'django_filters',
|
|
'drf_yasg',
|
|
'channels',
|
|
'django_seed',
|
|
'api',
|
|
'security',
|
|
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
'corsheaders.middleware.CorsMiddleware',
|
|
'django.middleware.common.CommonMiddleware',
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
|
|
]
|
|
|
|
ROOT_URLCONF = 'backend.urls'
|
|
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
STATIC_URL = os.getenv("STATIC_URL",'static/')
|
|
|
|
|
|
|
|
STATIC_ROOT = os.getenv('STATIC_ROOT', os.path.join(BASE_DIR, 'staticfiles'))
|
|
# Static files (CSS, JavaScript, Images)
|
|
STATICFILES_DIRS_PATH = os.getenv('STATICFILES_DIRS_PATH', 'static')
|
|
STATICFILES_DIRS = [
|
|
os.path.join(BASE_DIR, STATICFILES_DIRS_PATH),
|
|
]
|
|
|
|
|
|
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.debug',
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
# WSGI_APPLICATION = 'backend.wsgi.application'
|
|
ASGI_APPLICATION = 'backend.asgi.application' # asgi for websocket and channels
|
|
|
|
CHANNEL_LAYERS = {
|
|
'default': {
|
|
'BACKEND': 'channels_redis.core.RedisChannelLayer',
|
|
'CONFIG': {
|
|
"hosts": [('127.0.0.1', 6379)],
|
|
},
|
|
},
|
|
}
|
|
|
|
|
|
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
|
},
|
|
]
|
|
|
|
LANGUAGE_CODE = os.getenv("LANGUAGE_CODE",'en-us')
|
|
TIME_ZONE = os.getenv("TIME_ZONE",'UTC')
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
|
|
|
|
REST_FRAMEWORK = {
|
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
|
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
|
),
|
|
|
|
# 'DEFAULT_PERMISSION_CLASSES': [
|
|
# 'rest_framework.permissions.IsAuthenticated',
|
|
# 'api.permissions.CustomPermission'
|
|
# ],
|
|
|
|
#pagination
|
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
|
'PAGE_SIZE': int(os.getenv("PAGE_SIZE", '10')), # Number of items per page
|
|
|
|
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
|
|
}
|
|
|
|
SIMPLE_JWT = {
|
|
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=5),
|
|
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
|
|
"ROTATE_REFRESH_TOKENS": True,
|
|
"BLACKLIST_AFTER_ROTATION": True,
|
|
"UPDATE_LAST_LOGIN": False,
|
|
|
|
"ALGORITHM": "HS256",
|
|
"SIGNING_KEY": SECRET_KEY,
|
|
"VERIFYING_KEY": "",
|
|
"AUDIENCE": None,
|
|
"ISSUER": None,
|
|
"JSON_ENCODER": None,
|
|
"JWK_URL": None,
|
|
"LEEWAY": 0,
|
|
|
|
"AUTH_HEADER_TYPES": ("Bearer",),
|
|
"AUTH_HEADER_NAME": "HTTP_AUTHORIZATION",
|
|
"USER_ID_FIELD": "id",
|
|
"USER_ID_CLAIM": "user_id",
|
|
"USER_AUTHENTICATION_RULE": "rest_framework_simplejwt.authentication.default_user_authentication_rule",
|
|
|
|
"AUTH_TOKEN_CLASSES": ("rest_framework_simplejwt.tokens.AccessToken",),
|
|
"TOKEN_TYPE_CLAIM": "token_type",
|
|
"TOKEN_USER_CLASS": "rest_framework_simplejwt.models.TokenUser",
|
|
|
|
"JTI_CLAIM": "jti",
|
|
|
|
"SLIDING_TOKEN_REFRESH_EXP_CLAIM": "refresh_exp",
|
|
"SLIDING_TOKEN_LIFETIME": timedelta(minutes=5),
|
|
"SLIDING_TOKEN_REFRESH_LIFETIME": timedelta(days=1),
|
|
|
|
"TOKEN_OBTAIN_SERIALIZER": "rest_framework_simplejwt.serializers.TokenObtainPairSerializer",
|
|
"TOKEN_REFRESH_SERIALIZER": "rest_framework_simplejwt.serializers.TokenRefreshSerializer",
|
|
"TOKEN_VERIFY_SERIALIZER": "rest_framework_simplejwt.serializers.TokenVerifySerializer",
|
|
"TOKEN_BLACKLIST_SERIALIZER": "rest_framework_simplejwt.serializers.TokenBlacklistSerializer",
|
|
"SLIDING_TOKEN_OBTAIN_SERIALIZER": "rest_framework_simplejwt.serializers.TokenObtainSlidingSerializer",
|
|
"SLIDING_TOKEN_REFRESH_SERIALIZER": "rest_framework_simplejwt.serializers.TokenRefreshSlidingSerializer",
|
|
}
|
|
|
|
|
|
CORS_ALLOW_ALL_ORIGINS = True
|
|
|
|
CORS_ALLOW_METHODS = [
|
|
'DELETE',
|
|
'GET',
|
|
'OPTIONS',
|
|
'PATCH',
|
|
'POST',
|
|
'PUT',
|
|
]
|
|
|
|
CORS_ALLOW_HEADERS = [
|
|
'accept',
|
|
'accept-encoding',
|
|
'authorization',
|
|
'content-type',
|
|
'dnt',
|
|
'origin',
|
|
'user-agent',
|
|
'x-csrftoken',
|
|
'x-requested-with',
|
|
]
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------------
|
|
|
|
EMAIL_BACKEND = os.getenv("EMAIL_BACKEND")
|
|
EMAIL_HOST = os.getenv("EMAIL_HOST")
|
|
EMAIL_PORT = os.getenv("EMAIL_PORT")
|
|
EMAIL_USE_TLS = os.getenv("EMAIL_USE_TLS")
|
|
# EMAIL_USE_SSL = os.getenv("EMAIL_USE_SSL") == "False"
|
|
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
|
|
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
|
|
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD") |