""" Django settings for project project. Generated by 'django-admin startproject' using Django 6.0.2. For more information on this file, see https://docs.djangoproject.com/en/6.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/6.0/ref/settings/ """ # --- Import --- import os from pathlib import Path import environ import ldap from django_auth_ldap.config import LDAPSearch # --- Base Directory --- BASE_DIR = Path(__file__).resolve().parent.parent # --- Environment Initialization --- env = environ.Env() environ.Env.read_env(os.path.join(BASE_DIR, '.env')) # --- Security --- SECRET_KEY = env('SECRET_KEY') DEBUG = env.bool('DEBUG', default=False) ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=[]) # --- Custom User Model --- AUTH_USER_MODEL = 'core.CustomUserLogin' # --- LDAP Authentication --- AUTH_LDAP_SERVER_URI = env('AUTH_LDAP_SERVER_URI') AUTH_LDAP_BIND_DN = env('AUTH_LDAP_BIND_DN') AUTH_LDAP_BIND_PASSWORD = env('AUTH_LDAP_BIND_PASSWORD') AUTH_LDAP_USER_SEARCH = LDAPSearch( env('AUTH_LDAP_USER_SEARCH_BASE'), ldap.SCOPE_SUBTREE, env('AUTH_LDAP_USER_SEARCH_FILTER') ) AUTH_LDAP_CONNECTION_OPTIONS = { ldap.OPT_REFERRALS: 0, ldap.OPT_NETWORK_TIMEOUT: 5, } AUTH_LDAP_USER_ATTR_MAP = { "username": "sAMAccountName", "first_name": "givenName", "last_name": "sn", "email": "mail", } # --- Installed Applications --- INSTALLED_APPS = [ 'apps.core', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] 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', ] ROOT_URLCONF = 'project.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR / 'templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'apps.core.context_processors.titles', ], }, }, ] WSGI_APPLICATION = 'project.wsgi.application' # --- Database --- DATABASES = { 'default': { 'ENGINE': env('DB_ENGINE', default='django.db.backends.sqlite3'), 'NAME': BASE_DIR / env('DB_NAME', default='db.sqlite3'), 'USER': env('DB_USER', default=''), 'PASSWORD': env('DB_PASSWORD', default=''), 'HOST': env('DB_HOST', default=''), 'PORT': env('DB_PORT', default=''), } } # --- Password Validation --- 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'}, ] # --- Internationalization --- LANGUAGE_CODE = 'en-us' TIME_ZONE = 'Asia/Jakarta' USE_I18N = True USE_TZ = False # --- Static and Media Files --- STATIC_URL = 'static/' STATICFILES_DIRS = [BASE_DIR / 'static'] MEDIA_URL = 'media/' MEDIA_ROOT = BASE_DIR / 'media' # --- Default Primary Key --- DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' # --- Login / Logout URL --- LOGIN_URL = '/login/' LOGIN_REDIRECT_URL = '/' LOGOUT_REDIRECT_URL = '/'