"""
Django settings for asg_web_app project.

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

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

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

from authlib.integrations.django_client import OAuth
import os

# # disable the https check for development, should be deleted in production environment
# os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
# os.environ["OAUTHLIB_RELAX_TOKEN_SCOPE"] = "1"
# APPEND_SLASH = False
# 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/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'e3rl94#_#_k!0#syx&u8eja*vn##q^n=i#glcr))5o)ihs=4s^'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['asg-web-app-dev.ap-southeast-2.elasticbeanstalk.com', 'localhost', '127.0.0.1']

# Application definition

INSTALLED_APPS = [
    'user',
    'homepage',
    'gallery',
    'user_profile',
    'artworkpage',
    'booking',
    'captcha',
    'terms',
    'oauth',
    'django_countries',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'werkzeug_debugger_runserver',
    'django_extensions',
]

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 = 'asg_web_app.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',

        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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 = 'asg_web_app.wsgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

if 'RDS_DB_NAME' in os.environ:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': os.environ['RDS_DB_NAME'],
            'USER': os.environ['RDS_USERNAME'],
            'PASSWORD': os.environ['RDS_PASSWORD'],
            'HOST': os.environ['RDS_HOSTNAME'],
            'PORT': os.environ['RDS_PORT'],
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
    }

# Password validation
# https://docs.djangoproject.com/en/2.1/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',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/2.1/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/2.1/howto/static-files/


STATIC_URL = '/static/'
# STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static/'),
    # STATIC_ROOT,
    # ("css", os.path.join(STATIC_ROOT, "static")),
    # ("js", os.path.join(STATIC_ROOT, "js")),
]

# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# LOGIN_REDIRECT_URL = 'homeAfterLogin'
# LOGOUT_REDIRECT_URL = 'home'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

# TODO:change to your own setting
# used for sending email
EMAIL_HOST = "smtp.163.com"  # server
EMAIL_PORT = 25  # port number
EMAIL_HOST_USER = "15763036963@163.com"  # the account
EMAIL_HOST_PASSWORD = "LKEDMORRPCOTHSSE"  # password: the password used for Authorization of sending email, not the
# login
EMAIL_USE_TLS = False  # use transport layer security or not
EMAIL_FROM = "15763036963@163.com"  # which account send the email
# ACCOUNT_ACTIVATION_DAYS = 7  # One-week activation window; you may, of course, use a different value. currently
# didnt use

SESSION_EXPIRE_AT_BROWSER_CLOSE = True

# register the apps
oauth = OAuth()
