settings.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. ALLOWED_HOSTS=["*"]
  28. # Application definition
  29. CORS_ALLOWED_ORIGINS = [
  30. "http://188.72.209.29",
  31. "http://188.72.209.29:80",
  32. "http://188.72.209.29:8000",
  33. "http://localhost:8000",
  34. "http://127.0.0.1:3000",
  35. ]
  36. CORS_ALLOW_METHODS = [
  37. "GET",
  38. "POST",
  39. "PUT",
  40. "OPTIONS"
  41. ]
  42. INSTALLED_APPS = [
  43. 'django.contrib.admin',
  44. 'django.contrib.auth',
  45. 'django.contrib.contenttypes',
  46. 'django.contrib.sessions',
  47. 'django.contrib.messages',
  48. 'django.contrib.staticfiles',
  49. 'rest_framework',
  50. 'graphene_django',
  51. 'corsheaders',
  52. 'goods.apps.GoodsConfig',
  53. 'authAPI.apps.AuthAPIConfig',
  54. 'orders.apps.OrdersConfig',
  55. 'categories.apps.CategoriesConfig',
  56. ]
  57. MIDDLEWARE = [
  58. 'corsheaders.middleware.CorsMiddleware',
  59. 'django.middleware.security.SecurityMiddleware',
  60. 'django.contrib.sessions.middleware.SessionMiddleware',
  61. 'django.middleware.common.CommonMiddleware',
  62. # 'django.middleware.csrf.CsrfViewMiddleware',
  63. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  64. 'django.contrib.messages.middleware.MessageMiddleware',
  65. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  66. ]
  67. AUTHENTICATION_BACKENDS = [
  68. "graphql_jwt.backends.JSONWebTokenBackend",
  69. "django.contrib.auth.backends.ModelBackend",
  70. ]
  71. ROOT_URLCONF = 'store_back.urls'
  72. TEMPLATES = [
  73. {
  74. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  75. 'DIRS': [],
  76. 'APP_DIRS': True,
  77. 'OPTIONS': {
  78. 'context_processors': [
  79. 'django.template.context_processors.debug',
  80. 'django.template.context_processors.request',
  81. 'django.contrib.auth.context_processors.auth',
  82. 'django.contrib.messages.context_processors.messages',
  83. ],
  84. },
  85. },
  86. ]
  87. WSGI_APPLICATION = 'store_back.wsgi.application'
  88. AUTH_PASSWORD_VALIDATORS = [
  89. {
  90. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  91. },
  92. {
  93. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  94. },
  95. {
  96. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  97. },
  98. {
  99. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  100. },
  101. ]
  102. # Internationalization
  103. # https://docs.djangoproject.com/en/4.0/topics/i18n/
  104. LANGUAGE_CODE = 'en-us'
  105. TIME_ZONE = 'UTC'
  106. USE_I18N = True
  107. USE_TZ = True
  108. DATABASES = {
  109. 'default': {
  110. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  111. 'NAME': 'dfi11snf6cpamj',
  112. 'USER' : 'qvkowaptdjfexz',
  113. 'PASSWORD' : '3ef6f3a16c918da406cd2b388042a45080ff7f9dd10d5f9cc1df0ec0eca8ab7a',
  114. 'HOST' : 'ec2-52-48-159-67.eu-west-1.compute.amazonaws.com',
  115. 'PORT' : '5432',
  116. }
  117. }
  118. # Static files (CSS, JavaScript, Images)
  119. # https://docs.djangoproject.com/en/4.0/howto/static-files/
  120. STATIC_ROOT = os.path.join(BASE_DIR, 'static')
  121. STATIC_URL = '/static/'
  122. MEDIA_ROOT = os.path.join(BASE_DIR, 'media').replace('\\', '/')
  123. MEDIA_URL = '/api/media/'
  124. # Default primary key field type
  125. # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
  126. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  127. GRAPHENE = {
  128. 'SCHEMA': 'store_back.schema',
  129. "MIDDLEWARE": [
  130. "graphql_jwt.middleware.JSONWebTokenMiddleware",
  131. ],
  132. }
  133. GRAPHQL_JWT = {
  134. 'JWT_PAYLOAD_HANDLER': 'store_back.utils.jwt_payload',
  135. 'JWT_AUTH_HEADER_PREFIX': 'Bearer',
  136. 'JWT_VERIFY_EXPIRATION': True,
  137. 'JWT_LONG_RUNNING_REFRESH_TOKEN': True,
  138. 'JWT_EXPIRATION_DELTA': timedelta(days=30),
  139. 'JWT_REFRESH_EXPIRATION_DELTA':timedelta(days=1),
  140. 'JWT_SECRET_KEY': SECRET_KEY,
  141. 'JWT_ALGORITHM': 'HS256',
  142. }
  143. SIMPLE_JWT = {
  144. 'ACCESS_TOKEN_LIFETIME': timedelta(days=30),
  145. 'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
  146. 'ROTATE_REFRESH_TOKENS': False,
  147. 'BLACKLIST_AFTER_ROTATION': False,
  148. 'UPDATE_LAST_LOGIN': False,
  149. 'ALGORITHM': 'HS256',
  150. 'SIGNING_KEY': SECRET_KEY,
  151. 'VERIFYING_KEY': None,
  152. 'AUDIENCE': None,
  153. 'ISSUER': None,
  154. 'JWK_URL': None,
  155. 'LEEWAY': 0,
  156. 'AUTH_HEADER_TYPES': ('Bearer',),
  157. 'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION',
  158. 'USER_ID_FIELD': '_id',
  159. 'USER_ID_CLAIM': 'user_id',
  160. 'USER_AUTHENTICATION_RULE': 'rest_framework_simplejwt.authentication.default_user_authentication_rule',
  161. 'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
  162. 'TOKEN_TYPE_CLAIM': 'token_type',
  163. 'TOKEN_USER_CLASS': 'rest_framework_simplejwt.models.TokenUser',
  164. 'JTI_CLAIM': 'jti',
  165. 'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
  166. 'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5),
  167. 'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
  168. }
  169. REST_FRAMEWORK = {
  170. 'DEFAULT_AUTHENTICATION_CLASSES': (
  171. 'rest_framework_simplejwt.authentication.JWTAuthentication',
  172. )
  173. }