settings.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import os,sys
  2. from datetime import timedelta
  3. import django
  4. from django.utils.encoding import force_str
  5. django.utils.encoding.force_text = force_str
  6. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  7. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  8. PROJECT_ROOT = os.path.dirname(__file__)
  9. sys.path.insert(0,os.path.join(PROJECT_ROOT,'apps'))
  10. AUTH_USER_MODEL = 'authAPI.CustomUser'
  11. try:
  12. if os.environ['debug'] == 'False':
  13. DEBUG = False
  14. else:
  15. DEBUG = True
  16. except:
  17. DEBUG = True
  18. CORS_ORIGIN_ALLOW_ALL = True
  19. if DEBUG:
  20. SECRET_KEY = 'django-insecure-e*vqkvk_c%y&(v-^isb_%uwxq#y4eun3xhf4al_5f_)&14e5f0'
  21. else:
  22. try:
  23. SECRET_KEY = os.environ["SECRET_KEY"]
  24. except KeyError as e:
  25. raise RuntimeError("Could not find a SECRET_KEY in environment") from e
  26. from .prod import *
  27. # Application definition
  28. INSTALLED_APPS = [
  29. 'django.contrib.admin',
  30. 'django.contrib.auth',
  31. 'django.contrib.contenttypes',
  32. 'django.contrib.sessions',
  33. 'django.contrib.messages',
  34. 'django.contrib.staticfiles',
  35. 'rest_framework',
  36. 'graphene_django',
  37. 'corsheaders',
  38. 'goods.apps.GoodsConfig',
  39. 'authAPI.apps.AuthAPIConfig',
  40. 'orders.apps.OrdersConfig',
  41. 'categories.apps.CategoriesConfig',
  42. ]
  43. MIDDLEWARE = [
  44. 'django.middleware.security.SecurityMiddleware',
  45. 'django.contrib.sessions.middleware.SessionMiddleware',
  46. 'corsheaders.middleware.CorsMiddleware',
  47. 'django.middleware.common.CommonMiddleware',
  48. # 'django.middleware.csrf.CsrfViewMiddleware',
  49. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  50. 'django.contrib.messages.middleware.MessageMiddleware',
  51. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  52. ]
  53. AUTHENTICATION_BACKENDS = [
  54. "graphql_jwt.backends.JSONWebTokenBackend",
  55. "django.contrib.auth.backends.ModelBackend",
  56. ]
  57. ROOT_URLCONF = 'store_back.urls'
  58. TEMPLATES = [
  59. {
  60. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  61. 'DIRS': [],
  62. 'APP_DIRS': True,
  63. 'OPTIONS': {
  64. 'context_processors': [
  65. 'django.template.context_processors.debug',
  66. 'django.template.context_processors.request',
  67. 'django.contrib.auth.context_processors.auth',
  68. 'django.contrib.messages.context_processors.messages',
  69. ],
  70. },
  71. },
  72. ]
  73. WSGI_APPLICATION = 'store_back.wsgi.application'
  74. AUTH_PASSWORD_VALIDATORS = [
  75. {
  76. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  77. },
  78. {
  79. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  80. },
  81. {
  82. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  83. },
  84. {
  85. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  86. },
  87. ]
  88. # Internationalization
  89. # https://docs.djangoproject.com/en/4.0/topics/i18n/
  90. LANGUAGE_CODE = 'en-us'
  91. TIME_ZONE = 'UTC'
  92. USE_I18N = True
  93. USE_TZ = True
  94. DATABASES = {
  95. 'default': {
  96. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  97. 'NAME': 'dfi11snf6cpamj',
  98. 'USER' : 'qvkowaptdjfexz',
  99. 'PASSWORD' : '3ef6f3a16c918da406cd2b388042a45080ff7f9dd10d5f9cc1df0ec0eca8ab7a',
  100. 'HOST' : 'ec2-52-48-159-67.eu-west-1.compute.amazonaws.com',
  101. 'PORT' : '5432',
  102. }
  103. }
  104. # Static files (CSS, JavaScript, Images)
  105. # https://docs.djangoproject.com/en/4.0/howto/static-files/
  106. STATIC_ROOT = os.path.join(BASE_DIR, 'static')
  107. STATIC_URL = 'api/static/'
  108. MEDIA_ROOT = os.path.join(BASE_DIR, 'media').replace('\\', '/')
  109. MEDIA_URL = 'api/media/'
  110. # Default primary key field type
  111. # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
  112. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  113. GRAPHENE = {
  114. 'SCHEMA': 'store_back.schema',
  115. "MIDDLEWARE": [
  116. "graphql_jwt.middleware.JSONWebTokenMiddleware",
  117. ],
  118. }
  119. GRAPHQL_JWT = {
  120. 'JWT_PAYLOAD_HANDLER': 'store_back.utils.jwt_payload',
  121. 'JWT_AUTH_HEADER_PREFIX': 'Bearer',
  122. 'JWT_VERIFY_EXPIRATION': True,
  123. 'JWT_LONG_RUNNING_REFRESH_TOKEN': True,
  124. 'JWT_EXPIRATION_DELTA': timedelta(days=30),
  125. 'JWT_REFRESH_EXPIRATION_DELTA':timedelta(days=1),
  126. 'JWT_SECRET_KEY': SECRET_KEY,
  127. 'JWT_ALGORITHM': 'HS256',
  128. }
  129. SIMPLE_JWT = {
  130. 'ACCESS_TOKEN_LIFETIME': timedelta(days=30),
  131. 'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
  132. 'ROTATE_REFRESH_TOKENS': False,
  133. 'BLACKLIST_AFTER_ROTATION': False,
  134. 'UPDATE_LAST_LOGIN': False,
  135. 'ALGORITHM': 'HS256',
  136. 'SIGNING_KEY': SECRET_KEY,
  137. 'VERIFYING_KEY': None,
  138. 'AUDIENCE': None,
  139. 'ISSUER': None,
  140. 'JWK_URL': None,
  141. 'LEEWAY': 0,
  142. 'AUTH_HEADER_TYPES': ('Bearer',),
  143. 'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION',
  144. 'USER_ID_FIELD': '_id',
  145. 'USER_ID_CLAIM': 'user_id',
  146. 'USER_AUTHENTICATION_RULE': 'rest_framework_simplejwt.authentication.default_user_authentication_rule',
  147. 'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
  148. 'TOKEN_TYPE_CLAIM': 'token_type',
  149. 'TOKEN_USER_CLASS': 'rest_framework_simplejwt.models.TokenUser',
  150. 'JTI_CLAIM': 'jti',
  151. 'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
  152. 'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5),
  153. 'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
  154. }
  155. REST_FRAMEWORK = {
  156. 'DEFAULT_AUTHENTICATION_CLASSES': (
  157. 'rest_framework_simplejwt.authentication.JWTAuthentication',
  158. )
  159. }