"""
Django settings for BookReviewsProject project.

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

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

# 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 = '(dbv#2@z@4)-8yp*h+@qf&7!9-ika@o2&=2=#+20^^a_c8#hgn'

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

ALLOWED_HOSTS = ["*"]


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    
    # To prettify forms
    'crispy_forms',
    
    # Authentication apps to be installed
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',

    # My Apps
    'books',
    'reviews',
]

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

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        
        # Tell Django where to find the master template and the overridden templates
        'DIRS': [os.path.join(BASE_DIR, 'templates'),
                 os.path.join(BASE_DIR, 'templates', 'allauth')],
        
        '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',
            ],
        },
    },
]

# Settings for Authentication
# -------------- START AUTHENTICATION SETTINGS -------------- #

AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',

    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',
)

#  Allauth will need a site id to be used to identify the site
SITE_ID = 1

# Authentication method refers to how we want the user to log in.
# "username_email" means the user can log in via their username or email
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'

# Email required indicates whether the user must provide a valid email address when registering
ACCOUNT_EMAIL_REQUIRED = True

# Email verification indicates whether the user must verify the email address
# (by clicking on a special link sent to their email address) before they can sign in.
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'

# The "Email enter twice" basically requires the user to type in their email twice to prevent misspellings.
ACCOUNT_SIGNUP_EMAIL_ENTER_TWICE = True

# The minimum length of the account username
ACCOUNT_USERNAME_MIN_LENGTH = 4

# The LOGIN_URL determine the URL to the login page
LOGIN_URL = '/accounts/login/'

# LOGIN_REDIRECT_URL controls which page Django will show when the log is successful.
LOGIN_REDIRECT_URL = '/success'

# To simulate Django sending out emails. This will be seen in the console
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# -------------- END AUTHENTICATION SETTINGS -------------- #

WSGI_APPLICATION = 'BookReviewsProject.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# 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 = 'UTC'

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/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]

# To enable django to show flash message
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'

# To use bootstrap 4 form format
CRISPY_TEMPLATE_PACK = 'bootstrap4'