· 6 years ago · Jun 28, 2019, 03:58 PM
1# settings.py
2
3import os, sys
4from . local_settings import *
5import datetime
6# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
7BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
8
9# Quick-start development settings - unsuitable for production
10# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
11
12# SECURITY WARNING: keep the secret key used in production secret!
13SECRET_KEY = SECRET_KEY
14# SECURITY WARNING: don't run with debug turned on in production!
15
16DEBUG = (sys.argv[1] == 'runserver')
17
18ALLOWED_HOSTS = ['*']
19
20# Application definition
21
22INSTALLED_APPS = [
23 'django.contrib.admin',
24 'django.contrib.auth',
25 'django.contrib.contenttypes',
26 'django.contrib.sessions',
27 'django.contrib.messages',
28 'django.contrib.staticfiles',
29 'django.contrib.sites',
30
31 'allauth',
32 'allauth.account',
33 'allauth.socialaccount',
34 'allauth.socialaccount.providers.facebook',
35 'allauth.socialaccount.providers.google',
36
37 'webpack_loader',
38
39 'corsheaders',
40
41 'rest_framework',
42 'rest_auth',
43 'rest_auth.registration',
44 'rest_framework_swagger',
45
46 'app'
47]
48
49SITE_ID = 1
50
51MIDDLEWARE = [
52 'django.middleware.security.SecurityMiddleware',
53 'django.contrib.sessions.middleware.SessionMiddleware',
54 'django.middleware.common.CommonMiddleware',
55 'django.middleware.csrf.CsrfViewMiddleware',
56 'django.contrib.auth.middleware.AuthenticationMiddleware',
57 'django.contrib.messages.middleware.MessageMiddleware',
58 'django.middleware.clickjacking.XFrameOptionsMiddleware',
59 'corsheaders.middleware.CorsMiddleware',
60]
61
62ROOT_URLCONF = 'english_fighter3.urls'
63
64TEMPLATES = [
65 {
66 'BACKEND': 'django.template.backends.django.DjangoTemplates',
67 'DIRS': [os.path.join(BASE_DIR)],
68 'APP_DIRS': True,
69 'OPTIONS': {
70 'context_processors': [
71 'django.template.context_processors.debug',
72 'django.template.context_processors.request',
73 'django.contrib.auth.context_processors.auth',
74 'django.contrib.messages.context_processors.messages',
75 'django.template.context_processors.static',
76 ],
77 },
78 },
79]
80
81WSGI_APPLICATION = 'hello_world.wsgi.application'
82
83
84# Database
85# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
86
87DATABASES = {
88 'default': {
89 'ENGINE': 'django.db.backends.postgresql_psycopg2',
90 'NAME': NAME,
91 'USER': USER,
92
93 'PASSWORD': PASSWORD,
94 'HOST': HOST,
95 'PORT': PORT,
96 }
97}
98
99
100# Password validation
101# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
102
103AUTH_PASSWORD_VALIDATORS = [
104 {
105 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
106 },
107 {
108 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
109 },
110 {
111 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
112 },
113 {
114 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
115 },
116]
117
118
119# Internationalization
120# https://docs.djangoproject.com/en/2.1/topics/i18n/
121
122LANGUAGE_CODE = 'en-us'
123
124TIME_ZONE = 'UTC'
125
126USE_I18N = True
127
128USE_L10N = True
129
130USE_TZ = True
131
132
133# Static files (CSS, JavaScript, Images)
134# https://docs.djangoproject.com/en/2.1/howto/static-files/
135
136STATIC_URL = '/static/'
137
138STATIC_ROOT = '/var/www/englishfighter3/staticfiles/'
139
140STATICFILES_DIRS = [
141 os.path.join(BASE_DIR, 'dist'),
142 os.path.join(BASE_DIR, 'static'),
143]
144
145WEBPACK_LOADER = {
146 'DEFAULT': {
147 'CACHE': not DEBUG,
148 # 'BUNDLE_DIR_NAME': 'webpack_bundles/', # must end with slash
149 'BUNDLE_DIR_NAME': '', # must end with slash
150 'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
151 'POLL_INTERVAL': 0.1,
152 'TIMEOUT': None,
153 'IGNORE': [r'.+\.hot-update.js', r'.+\.map']
154 }
155}
156
157REST_FRAMEWORK = {
158 'DEFAULT_PERMISSION_CLASSES': (
159 'rest_framework.permissions.IsAuthenticated',
160 ),
161 'DEFAULT_AUTHENTICATION_CLASSES': (
162 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
163 # 'rest_framework.authentication.TokenAuthentication',
164
165 # =========================================
166 # 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
167 # 'rest_framework_simplejwt.authentication.JWTAuthentication',
168 # 'rest_framework.authentication.BasicAuthentication',
169 # 'rest_framework.authentication.SessionAuthentication',
170 # =========================================
171
172 # 'rest_framework.authentication.SessionAuthentication',
173 # 'rest_framework.authentication.BasicAuthentication',
174 ),
175 # 'DEFAULT_PARSER_CLASSES': (
176 # 'rest_framework.parsers.JSONParser',
177 # 'rest_framework.parsers.FormParser',
178 # 'rest_framework.parsers.MultiPartParser',
179 # )
180}
181
182AUTHENTICATION_BACKENDS = (
183 "django.contrib.auth.backends.ModelBackend",
184 "allauth.account.auth_backends.AuthenticationBackend"
185)
186
187REST_USE_JWT = True
188CORS_ORIGIN_ALLOW_ALL = True
189
190JWT_AUTH = {
191
192 # 'JWT_LEEWAY': 0,
193
194 'JWT_ALLOW_REFRESH': True,
195
196 # 'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=1),
197 'JWT_EXPIRATION_DELTA': datetime.timedelta(True),
198 'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
199
200 # 'JWT_AUTH_COOKIE': 'JWT',
201
202 # 'JWT_EXPIRATION_DELTA': datetime.timedelta(True),
203}
204
205EMAIL_HOST = 'smtp.gmail.com'
206EMAIL_HOST_USER = 'helloWorld@gmail.com'
207EMAIL_HOST_PASSWORD = 'helloWorld'
208EMAIL_PORT = 587
209EMAIL_USE_TLS = True
210
211LOGIN_REDIRECT_URL='/'
212# ACCOUNT_EMAIL_VERIFICATION='mandatory'
213# ACCOUNT_EMAIL_REQUIRED = True
214# ACCOUNT_CONFIRM_EMAIL_ON_GET=False
215# ACCOUNT_USERNAME_REQUIRED = True
216# ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = False
217
218
219
220# ACCOUNT_AUTHENTICATION_METHOD = 'username'
221# ACCOUNT_EMAIL_REQUIRED = True
222# ACCOUNT_USERNAME_REQUIRED = False
223# ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
224
225# REST_REGISTRATION = {
226# 'REGISTER_VERIFICATION_URL': 'http://localhost:8000/verify-user/',
227# 'RESET_PASSWORD_VERIFICATION_URL': 'http://localhost:8000/reset-password/',
228# 'REGISTER_EMAIL_VERIFICATION_URL': 'http://localhost:8000/login/',
229
230# 'VERIFICATION_FROM_EMAIL': 'no-reply@example.com',
231# }
232
233# urls.py
234
235from django.conf import settings
236from django.contrib import admin
237from django.urls import path, re_path, include
238
239from rest_framework_swagger.views import get_swagger_view
240
241swagger = get_swagger_view(title='EglishFighter API')
242
243from django.views.static import serve
244from django.views.generic import TemplateView
245from django.contrib.staticfiles.urls import staticfiles_urlpatterns
246
247from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token
248
249from allauth.account.views import confirm_email as allauthemailconfirmation
250
251urlpatterns = [
252 path('admin/', admin.site.urls),
253 path('app/', include('app.urls')),
254 path('swagger/', swagger),
255
256
257 path('rest-auth/', include('rest_auth.urls')),
258 path('rest-auth/registration/', include('rest_auth.registration.urls')),
259
260
261 re_path(r'^rest-auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$', allauthemailconfirmation,
262 name='account_confirm_email'),
263
264 # path('accounts/', include('rest_registration.api.urls')),
265
266 path('auth/obtain_token/', obtain_jwt_token),
267 path('auth/refresh_token/', refresh_jwt_token),
268
269 re_path(r'', TemplateView.as_view(template_name='index.html'), name='home'),
270 re_path(r'^accounts/', include('allauth.urls'))
271]
272
273urlpatterns += staticfiles_urlpatterns()