"""
Django settings for refugios 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/
"""

import os

 
 

# 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 = 'x%o==2uv0_d0w4=*(tb20u+vqdq252-5bdgig61v&9mg9-0wy1'

# 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',
    'refugio',
    'django_adminlte',
    'django_adminlte_theme',
    'django.contrib.sites',
    'registration', #should be immediately above 'django.contrib.admin'
    'rest_framework',
    'social_django',
    'social.apps.django_app.default',

# ...other installed appl
]
SITE_ID = 1
ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
REGISTRATION_AUTO_LOGIN = True # Automatically log the user in.

REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ]
}

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',
    'social_django.middleware.SocialAuthExceptionMiddleware' ,
]

AUTHENTICATION_BACKENDS=(
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
    'social_core.backends.open_id.OpenIdAuth' ,
    'social_core.backends.google.GoogleOpenId' ,
    'social_core.backends.google.GoogleOAuth2' ,
    'social_core.backends.google.GoogleOAuth' ,
         
)
TEMPLATE_CONTEXT_PROCESSORS = (
    
    'social.apps.django_app.context_processors.backends',
    'social.apps.django_app.context_processors.login_redirect',
)
ROOT_URLCONF = 'refugios.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'refugios/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',
                'social_django.context_processors.login_redirect',
            ],
        },
    },
]

WSGI_APPLICATION = 'refugios.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME':'prueba8',
        'USER':'postgres',
        'PASSWORD':'123',
        'HOST':'localhost',
        'PORT':5432,
    }
}


# 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',
    },
]
SOCIAL_AUTH_PIPELINE = (
    # recibe vía backend y uid las instancias de social_user y user
    'social.pipeline.social_auth.social_details',

    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',

    # Recibe según user.email la instancia del usuario y lo reemplaza con uno que recibió anteriormente
    'social.pipeline.social_auth.social_user',

    # Trata de crear un username válido según los datos que recibe
    'social.pipeline.user.get_username',

    # Crea un usuario nuevo si uno todavía no existe
    'social.pipeline.user.create_user',

    # Trata de conectar las cuentas
    'social.pipeline.social_auth.associate_user',

    # Recibe y actualiza social_user.extra_data
    'social.pipeline.social_auth.load_extra_data',

    # Actualiza los campos de la instancia user con la información que obtiene vía backend
    'social.pipeline.user.user_details',
)

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

LANGUAGE_CODE = 'es-CO'

TIME_ZONE = 'America/Bogota'

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/'
MEDIA_ROOT=os.path.join(BASE_DIR,'media/')

STATICFILES_DIRS = (
 os.path.join(BASE_DIR, 'media'),
)

SOCIAL_AUTH_URL_NAMESPACE = 'social'
SOCIAL_AUTH_POSTGRES_JSONFIELD = True
SOCIAL_AUTH_LOGIN_REDIRECT_URL='/'
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '945199752428-lqe77kgkij2ts29rrvvkrcgii46plujj.apps.googleusercontent.com'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'Z_BBtbBUo007DuBCT5_KSNjK'

LOGGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'frameworksumariana@gmail.com'
EMAIL_HOST_PASSWORD = 'ingsis604'
EMAIL_PORT =  587

