Fakultas Ilmu Komputer UI

settings.py 6.05 KB
Newer Older
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
1
2
3
4
5
6
7
8
9
10
11
12
"""
Django settings for pplbackend project.

Generated by 'django-admin startproject' using Django 3.0.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

13
import dj_database_url
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
14
import os
Usman Sidiq's avatar
Usman Sidiq committed
15
from datetime import timedelta
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
16
17
18
19
20
21
22
23

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

24
#Security keys
25
SECRET_KEY = os.getenv('SECRET_KEY', 'akua')
26

27

Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
28
# SECURITY WARNING: don't run with debug turned on in production!
29
DEBUG = True
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
30

Bayukanta Iqbal Gunawan's avatar
a    
Bayukanta Iqbal Gunawan committed
31
ALLOWED_HOSTS = ['*']
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
32
33
34
35
36
37
38


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
39
    'django.contrib.sites',
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
40
41
42
43
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
44
    'django.contrib.auth.hashers',
45
    'registrasi',
46
    'informasi_fasilitas',
47
    'new_rest_api',
48
    'layanan_khusus',
49
50
51
52
53
54
55
56
57

    'rest_auth',
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth.registration',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
58
    'multiselectfield',
59
    'oauth2_provider',
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

ROOT_URLCONF = 'pplbackend.urls'

75
TEMPLATES_ROOT = os.path.join(BASE_DIR, "templates")
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
76
77
78
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
79
        'DIRS': [TEMPLATES_ROOT],
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
        '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 = 'pplbackend.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
    'default': {
100
101
102
103
104
105
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('DB_NAME', 'postgres'),
        'USER': os.environ.get('DB_USER', 'postgres'),
        'PASSWORD': os.environ.get('DB_PASSWORD', 'postgres'),
        'HOST': os.environ.get('DB_HOST', 'localhost'),
        'PORT': os.environ.get('DB_PORT', '5432'),
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
106
107
108
    }
}

109
110
111
112
if os.environ.get("DATABASE_URL"):
    DATABASES['default'] = dj_database_url.config()


Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

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',
    },
]

132
133
134
135
136
137
# AUTH_USER_MODEL = 'registrasi.BisaGoUser'
# ACCOUNT_AUTHENTICATION_METHOD = 'email'
# ACCOUNT_EMAIL_REQUIRED = True
# ACCOUNT_UNIQUE_EMAIL = True
# ACCOUNT_USER_MODEL_USERNAME_FIELD = None
# ACCOUNT_USERNAME_REQUIRED = False
138

Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

Bayukanta Iqbal Gunawan's avatar
a    
Bayukanta Iqbal Gunawan committed
157
158
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
159
STATIC_URL = '/static/'
Bayukanta Iqbal Gunawan's avatar
a    
Bayukanta Iqbal Gunawan committed
160
161
162
163

STATIC_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
164
165
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#Rest API Settings
SITE_ID = 1

AUTHENTICATION_BACKENDS = [
    # Default backend -- used to login by username in Django admin
    "django.contrib.auth.backends.ModelBackend",
    # `allauth` specific authentication methods, such as login by e-mail
    "allauth.account.auth_backends.AuthenticationBackend",
]

ACCOUNT_DEFAULT_HTTP_PROTOCOL = "http"

SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'SCOPE': [
            'profile',
            'email',
        ],
        'AUTH_PARAMS': {
            'access_type': 'online',
        }
    }
}

LOGIN_REDIRECT_URL = '/'
REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
193
194
195
196
    'PAGE_SIZE': 10,
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
197
        'rest_framework.authentication.TokenAuthentication',
Usman Sidiq's avatar
Usman Sidiq committed
198
        'rest_framework_simplejwt.authentication.JWTAuthentication',
199
200
201
202
    ],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',
    ],
203
}
204
205
206
207
208
209
210

PASSWORD_HASHERS = [
    'django.contrib.auth.hashers.PBKDF2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
    'django.contrib.auth.hashers.Argon2PasswordHasher',
    'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
]
211
212
213
214
215

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")
Usman Sidiq's avatar
Usman Sidiq committed
216
217
218
219
220
221
222
223
224
225
226
EMAIL_PORT = 587

MEDIA_URL =  '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
GOOGLE_OAUTH2_CLIENT_ID = os.getenv("GOOGLE_OAUTH2_CLIENT_ID")
GOOGLE_OAUTH2_CLIENT_SECRET = os.getenv("GOOGLE_OAUTH_CLIENT_SECRET")

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(days=1),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=90),
}