"""
Django settings for project project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
import sys

# import django_heroku

# Title: In 5 mins: Set up Google login to sign up users on Django <br>
# Author: Zoe Chew <br>
# Date: 03/03/21 <br>
# URL: https://whizzoe.medium.com/in-5-mins-set-up-google-login-to-sign-up-users-on-django-e71d5c38f5d5 <br>

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&u=+3twv5cl(jw-uvtbeng=_58pa^wosv0(o27#=@u6s2q5m!s'

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

ALLOWED_HOSTS = []

# SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
# Application definition

INSTALLED_APPS = [
    'djangosecure',
    'sslserver',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # Updated the installed apps (03/01/21)
    'django.contrib.sites',
    'crispy_forms',
    'exercise.apps.ExerciseConfig',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
    'django_oso'

    # 'exercise',
]

# Added 03/22
# AUTH_USER_MODEL = 'exercise.User'


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.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'project.wsgi.application'


# Database
# The following stack overflow answer aided in writing the if else condition used for our database configuration 
# Title: Django configuring different databases
# Author: itzMEonTV
# Date: 04/29/21
# URL: https://stackoverflow.com/questions/47579644/django-configuring-different-databases

# Title: DATABASES
# Author: Django Documentation
# Date: 04/29/21
# URL: https://docs.djangoproject.com/en/3.1/ref/settings/#databases

# Title: How to use PostgreSQL with Django
# Author: Richard Yen
# Date: 04/29/21
# URL: https://www.enterprisedb.com/postgres-tutorials/how-use-postgresql-django?fbclid=IwAR22uppxhHcUSnvO73roHVYH3qzRzmP3687S7krh1844c5N49h2l7VTKrrA

# The below reference was critical in helping to debug an issue with Travis and automated testing:
# Title: Provisioning a Test PostgreSQL database on Heroku for your Django App
# Author: Sola-Aremu 'Pelumi
# Date: 04/29/21
# URL: https://medium.com/analytics-vidhya/provisioning-a-test-postgresql-database-on-heroku-for-your-django-app-febb2b5d3b29

## Testing DB (using sqlite)
if 'test' in sys.argv:
    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
            'TEST': {
                'NAME': BASE_DIR / 'db.sqlite3', 
            }
        }
    }
## Development 
else:
    DATABASES = { 
    'default': 
    {
        'ENGINE':'django.db.backends.postgresql_psycopg2',
        'NAME': 'dcd2j05latd35a',
        'USER': 'kkkifpshjwhhue',
        'PASSWORD': '456391adf83d19807c430d193ccfe73c37ea28affa4933d4a9e2eb17913f5c8a',
        'HOST': 'ec2-54-198-73-79.compute-1.amazonaws.com',
        'PORT': '5432'
    },
}

## Production 
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=600)
DATABASES['default'].update(db_from_env)

SESSION_EXPIRE_AT_BROWSER_CLOSE = True

# Password validation
# https://docs.djangoproject.com/en/3.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/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/New_York'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

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

# Specified 'allauth' backend (03/01/21)
AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
)

# Added site id and also specified the redirect URL
# SITE_ID = 0
# Use 5 when deploying to Heroku
SITE_ID = 5
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

# Added 03/22
# ACCOUNT_EMAIL_VERIFICATION = "none"
# ACCOUNT_LOGOUT_ON_GET = True
# ACCOUNT_USER_MODEL_USERNAME_FIELD = None
# ACCOUNT_EMAIL_REQUIRED = True
# ACCOUNT_USERNAME_REQUIRED = False
# ACCOUNT_AUTHENTICATION_METHOD = 'email'

# Way to get user's email addresses when they log in
SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'SCOPE': [
            'profile',
            'email',
        ],
        'AUTH_PARAMS': {
            'access_type': 'online',
        }
    }
}
# Added 03/19/21
# AUTH_USER_MODEL = 'exercise.User'
# End

# Activate Django-Heroku.
try:
    # Configure Django App for Heroku.
    import django_heroku
    django_heroku.settings(locals())
except ImportError:
    found = False


b528d884d31f3ed57dfc59ad6d311f65c2202411
<mask token>

<mask token>
if 'test' in sys.argv:
    DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME':
        BASE_DIR / 'db.sqlite3', 'TEST': {'NAME': BASE_DIR / 'db.sqlite3'}}}
else:
    DATABASES = {'default': {'ENGINE':
        'django.db.backends.postgresql_psycopg2', 'NAME': 'dcd2j05latd35a',
        'USER': 'kkkifpshjwhhue', 'PASSWORD':
        '456391adf83d19807c430d193ccfe73c37ea28affa4933d4a9e2eb17913f5c8a',
        'HOST': 'ec2-54-198-73-79.compute-1.amazonaws.com', 'PORT': '5432'}}
<mask token>
DATABASES['default'].update(db_from_env)
<mask token>
try:
    import django_heroku
    django_heroku.settings(locals())
except ImportError:
    found = False

<mask token>
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = '&u=+3twv5cl(jw-uvtbeng=_58pa^wosv0(o27#=@u6s2q5m!s'
DEBUG = False
ALLOWED_HOSTS = []
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
INSTALLED_APPS = ['djangosecure', 'sslserver', 'django.contrib.admin',
    'django.contrib.auth', 'django.contrib.contenttypes',
    'django.contrib.sessions', 'django.contrib.messages',
    'django.contrib.staticfiles', 'django.contrib.sites', 'crispy_forms',
    'exercise.apps.ExerciseConfig', 'allauth', 'allauth.account',
    'allauth.socialaccount', 'allauth.socialaccount.providers.google',
    'django_oso']
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.debug',
    'django.template.context_processors.request',
    'django.contrib.auth.context_processors.auth',
    'django.contrib.messages.context_processors.messages']}}]
WSGI_APPLICATION = 'project.wsgi.application'
if 'test' in sys.argv:
    DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME':
        BASE_DIR / 'db.sqlite3', 'TEST': {'NAME': BASE_DIR / 'db.sqlite3'}}}
else:
    DATABASES = {'default': {'ENGINE':
        'django.db.backends.postgresql_psycopg2', 'NAME': 'dcd2j05latd35a',
        'USER': 'kkkifpshjwhhue', 'PASSWORD':
        '456391adf83d19807c430d193ccfe73c37ea28affa4933d4a9e2eb17913f5c8a',
        'HOST': 'ec2-54-198-73-79.compute-1.amazonaws.com', 'PORT': '5432'}}
<mask token>
db_from_env = dj_database_url.config(conn_max_age=600)
DATABASES['default'].update(db_from_env)
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
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'}
    ]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/New_York'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend')
SITE_ID = 5
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
SOCIALACCOUNT_PROVIDERS = {'google': {'SCOPE': ['profile', 'email'],
    'AUTH_PARAMS': {'access_type': 'online'}}}
try:
    import django_heroku
    django_heroku.settings(locals())
except ImportError:
    found = False

<mask token>
import os
from pathlib import Path
import sys
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = '&u=+3twv5cl(jw-uvtbeng=_58pa^wosv0(o27#=@u6s2q5m!s'
DEBUG = False
ALLOWED_HOSTS = []
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
INSTALLED_APPS = ['djangosecure', 'sslserver', 'django.contrib.admin',
    'django.contrib.auth', 'django.contrib.contenttypes',
    'django.contrib.sessions', 'django.contrib.messages',
    'django.contrib.staticfiles', 'django.contrib.sites', 'crispy_forms',
    'exercise.apps.ExerciseConfig', 'allauth', 'allauth.account',
    'allauth.socialaccount', 'allauth.socialaccount.providers.google',
    'django_oso']
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.debug',
    'django.template.context_processors.request',
    'django.contrib.auth.context_processors.auth',
    'django.contrib.messages.context_processors.messages']}}]
WSGI_APPLICATION = 'project.wsgi.application'
if 'test' in sys.argv:
    DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME':
        BASE_DIR / 'db.sqlite3', 'TEST': {'NAME': BASE_DIR / 'db.sqlite3'}}}
else:
    DATABASES = {'default': {'ENGINE':
        'django.db.backends.postgresql_psycopg2', 'NAME': 'dcd2j05latd35a',
        'USER': 'kkkifpshjwhhue', 'PASSWORD':
        '456391adf83d19807c430d193ccfe73c37ea28affa4933d4a9e2eb17913f5c8a',
        'HOST': 'ec2-54-198-73-79.compute-1.amazonaws.com', 'PORT': '5432'}}
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=600)
DATABASES['default'].update(db_from_env)
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
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'}
    ]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/New_York'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend')
SITE_ID = 5
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
SOCIALACCOUNT_PROVIDERS = {'google': {'SCOPE': ['profile', 'email'],
    'AUTH_PARAMS': {'access_type': 'online'}}}
try:
    import django_heroku
    django_heroku.settings(locals())
except ImportError:
    found = False

"""
Django settings for project project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
import sys

# import django_heroku

# Title: In 5 mins: Set up Google login to sign up users on Django <br>
# Author: Zoe Chew <br>
# Date: 03/03/21 <br>
# URL: https://whizzoe.medium.com/in-5-mins-set-up-google-login-to-sign-up-users-on-django-e71d5c38f5d5 <br>

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&u=+3twv5cl(jw-uvtbeng=_58pa^wosv0(o27#=@u6s2q5m!s'

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

ALLOWED_HOSTS = []

# SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
# Application definition

INSTALLED_APPS = [
    'djangosecure',
    'sslserver',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # Updated the installed apps (03/01/21)
    'django.contrib.sites',
    'crispy_forms',
    'exercise.apps.ExerciseConfig',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
    'django_oso'

    # 'exercise',
]

# Added 03/22
# AUTH_USER_MODEL = 'exercise.User'


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.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'project.wsgi.application'


# Database
# The following stack overflow answer aided in writing the if else condition used for our database configuration 
# Title: Django configuring different databases
# Author: itzMEonTV
# Date: 04/29/21
# URL: https://stackoverflow.com/questions/47579644/django-configuring-different-databases

# Title: DATABASES
# Author: Django Documentation
# Date: 04/29/21
# URL: https://docs.djangoproject.com/en/3.1/ref/settings/#databases

# Title: How to use PostgreSQL with Django
# Author: Richard Yen
# Date: 04/29/21
# URL: https://www.enterprisedb.com/postgres-tutorials/how-use-postgresql-django?fbclid=IwAR22uppxhHcUSnvO73roHVYH3qzRzmP3687S7krh1844c5N49h2l7VTKrrA

# The below reference was critical in helping to debug an issue with Travis and automated testing:
# Title: Provisioning a Test PostgreSQL database on Heroku for your Django App
# Author: Sola-Aremu 'Pelumi
# Date: 04/29/21
# URL: https://medium.com/analytics-vidhya/provisioning-a-test-postgresql-database-on-heroku-for-your-django-app-febb2b5d3b29

## Testing DB (using sqlite)
if 'test' in sys.argv:
    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
            'TEST': {
                'NAME': BASE_DIR / 'db.sqlite3', 
            }
        }
    }
## Development 
else:
    DATABASES = { 
    'default': 
    {
        'ENGINE':'django.db.backends.postgresql_psycopg2',
        'NAME': 'dcd2j05latd35a',
        'USER': 'kkkifpshjwhhue',
        'PASSWORD': '456391adf83d19807c430d193ccfe73c37ea28affa4933d4a9e2eb17913f5c8a',
        'HOST': 'ec2-54-198-73-79.compute-1.amazonaws.com',
        'PORT': '5432'
    },
}

## Production 
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=600)
DATABASES['default'].update(db_from_env)

SESSION_EXPIRE_AT_BROWSER_CLOSE = True

# Password validation
# https://docs.djangoproject.com/en/3.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/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/New_York'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

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

# Specified 'allauth' backend (03/01/21)
AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
)

# Added site id and also specified the redirect URL
# SITE_ID = 0
# Use 5 when deploying to Heroku
SITE_ID = 5
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

# Added 03/22
# ACCOUNT_EMAIL_VERIFICATION = "none"
# ACCOUNT_LOGOUT_ON_GET = True
# ACCOUNT_USER_MODEL_USERNAME_FIELD = None
# ACCOUNT_EMAIL_REQUIRED = True
# ACCOUNT_USERNAME_REQUIRED = False
# ACCOUNT_AUTHENTICATION_METHOD = 'email'

# Way to get user's email addresses when they log in
SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'SCOPE': [
            'profile',
            'email',
        ],
        'AUTH_PARAMS': {
            'access_type': 'online',
        }
    }
}
# Added 03/19/21
# AUTH_USER_MODEL = 'exercise.User'
# End

# Activate Django-Heroku.
try:
    # Configure Django App for Heroku.
    import django_heroku
    django_heroku.settings(locals())
except ImportError:
    found = False

