· 5 years ago · May 31, 2020, 04:32 PM
1"""
2Django settings for project project.
3
4Generated by 'django-admin startproject' using Django 2.1.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/2.1/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/2.1/ref/settings/
11"""
12
13import os
14import datetime
15import dj_database_url
16import environ
17
18# reading .env file
19environ.Env.read_env()
20
21# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
22PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
23BASE_DIR = os.path.dirname(PROJECT_ROOT)
24
25# Quick-start development settings - unsuitable for production
26# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
27
28# SECURITY WARNING: keep the secret key used in production secret!
29SECRET_KEY = os.environ.get('SECRET_KEY', 'verybadsecret!!!')
30
31# SECURITY WARNING: don't run with debug turned on in production!
32DEBUG = os.environ.get("DEBUG", "true").lower() != "false"
33
34ALLOWED_HOSTS = ['*']
35
36# Application definition
37
38INSTALLED_APPS = [
39 'django.contrib.admin',
40 'django.contrib.auth',
41 'django.contrib.contenttypes',
42 'django.contrib.sessions',
43 'django.contrib.messages',
44 'whitenoise.runserver_nostatic', # < Per Whitenoise, to disable built in
45 'django.contrib.staticfiles',
46 'rest_framework',
47 'rest_framework.authtoken',
48 'landing_page',
49 'pengumuman',
50 'permohonan_surat',
51 'karya_akhir',
52 'asdos',
53 'admin_birpen',
54 'safedelete',
55 'django_cas_ng',
56 'sso_ui.apps.SSOUIConfig',
57 'rest_framework_jwt',
58 'alumni',
59]
60
61MIDDLEWARE = [
62 'django.middleware.security.SecurityMiddleware',
63 'whitenoise.middleware.WhiteNoiseMiddleware',
64 'django.contrib.sessions.middleware.SessionMiddleware',
65 'django.middleware.common.CommonMiddleware',
66 'django.middleware.csrf.CsrfViewMiddleware',
67 'django.contrib.auth.middleware.AuthenticationMiddleware',
68 'django.contrib.messages.middleware.MessageMiddleware',
69 'django.middleware.clickjacking.XFrameOptionsMiddleware',
70]
71
72ROOT_URLCONF = 'birpen.urls'
73
74TEMPLATES = [
75 {
76 'BACKEND': 'django.template.backends.django.DjangoTemplates',
77 # Add dist to
78 'DIRS': ['dist'],
79 'APP_DIRS': True,
80 'OPTIONS': {
81 'context_processors': [
82 'django.template.context_processors.debug',
83 'django.template.context_processors.request',
84 'django.contrib.auth.context_processors.auth',
85 'django.contrib.messages.context_processors.messages',
86 ],
87 },
88 },
89]
90
91WSGI_APPLICATION = 'birpen.wsgi.application'
92
93# Database
94# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
95
96DATABASES = {
97 'default': {
98 'ENGINE': 'django.db.backends.postgresql_psycopg2',
99 'NAME': os.environ.get('DB_NAME', 'postgres'),
100 'USER': os.environ.get('DB_USER', 'postgres'),
101 'PASSWORD': os.environ.get('DB_PASSWORD', 'postgres'),
102 'HOST': os.environ.get('DB_HOST', 'localhost'),
103 'PORT': os.environ.get('DB_PORT', '5432'),
104 }
105}
106
107if os.environ.get("DATABASE_URL"):
108 DATABASES['default'] = dj_database_url.config()
109
110# Authentication backends
111# https://docs.djangoproject.com/en/2.1/topics/auth/customizing/#specifying-authentication-backends
112
113AUTHENTICATION_BACKENDS = (
114
115)
116
117# Django CAS-NG configuration
118
119CAS_SERVER_URL = os.getenv("CAS_SERVER_URL", 'https://sso.ui.ac.id/cas2/')
120CAS_LOGIN_URL_NAME = 'sso_ui:login'
121CAS_FORCE_CHANGE_USERNAME_CASE = 'lower'
122
123
124# SSO-UI configuration
125
126SSO_UI_ORG_DETAIL_FILE_PATH = "sso_ui/static/sso_ui/kodoru.json"
127SSO_UI_ORG_DETAIL_LANG = "id"
128
129# Password validation
130# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
131
132AUTH_PASSWORD_VALIDATORS = [
133 {
134 'NAME':
135 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
136 },
137 {
138 'NAME':
139 'django.contrib.auth.password_validation.MinimumLengthValidator',
140 },
141 {
142 'NAME':
143 'django.contrib.auth.password_validation.CommonPasswordValidator',
144 },
145 {
146 'NAME':
147 'django.contrib.auth.password_validation.NumericPasswordValidator',
148 },
149]
150
151# Internationalization
152# https://docs.djangoproject.com/en/2.1/topics/i18n/
153
154LANGUAGE_CODE = 'en-us'
155TIME_ZONE = 'Asia/Jakarta'
156USE_I18N = True
157USE_L10N = True
158USE_TZ = True
159
160# Static files (CSS, JavaScript, Images)
161# https://docs.djangoproject.com/en/2.1/howto/static-files/
162
163# When Vue Builds, path will be `/static/css/...` so we will have Django Serve
164# In Production, it's recommended use an alternative approach such as:
165# http://whitenoise.evans.io/en/stable/django.html?highlight=django
166
167MIDDLEWARE_CLASSES = ('whitenoise.middleware.WhiteNoiseMiddleware', )
168
169STATIC_URL = '/static/'
170# Place static in the same location as webpack build files
171STATIC_ROOT = os.path.join(BASE_DIR, 'dist', 'static')
172STATICFILES_DIRS = []
173
174##########
175# STATIC #
176##########
177
178STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
179
180
181AUTH_USER_MODEL = 'sso_ui.User'
182
183# Insert Whitenoise Middleware at top but below Security Middleware
184# MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware',)
185# http://whitenoise.evans.io/en/stable/django.html#make-sure-staticfiles-is-configured-correctly
186
187REST_FRAMEWORK = {
188 'DEFAULT_AUTHENTICATION_CLASSES': (
189 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
190 )
191}
192
193JWT_AUTH = {
194 'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=1800),
195}
196
197# Authentication backends
198# https://docs.djangoproject.com/en/2.1/topics/auth/customizing/#specifying-authentication-backends
199
200AUTHENTICATION_BACKENDS = (
201 'django.contrib.auth.backends.ModelBackend',
202 'django_cas_ng.backends.CASBackend',
203)
204
205CAS_REDIRECT_URL = '/sso/save_user_info/'