"""
Django settings for sp_sso project.

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

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

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

from django.conf import global_settings
from django.utils.translation import ugettext_lazy as _

BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Logger config copied from the authentic2 project settings:
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            },
    },
    'loggers': {
        'django.request': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
            'propagate': True,
        },
        'sp_sso.resource': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
            'propagate': True,
        },
    },
}

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3568aw3i!gv@xb_nloh0$(lz%^y-2-&ey_qx^i)&_j!26#q)73'

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

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = ['localhost', 'sp-condorcet.dev.entrouvert.org']

MELLON_HACK = True

TEMPLATE_DIRS = (
    'templates',
)

USE_I18N = False

AUTHENTICATION_BACKENDS = (
    'mellon.backends.SAMLBackend',
    'django.contrib.auth.backends.ModelBackend',
)

AUTH_USER_MODEL = 'saml.SupAnnUser'

LOGIN_REDIRECT_URL = '/logged_in/'
LOGIN_URL = '/login/'
LOGOUT_URL = '/logout/'

MELLON_ATTRIBUTE_MAPPING = {
    'first_name': '{attributes[fname_test][0]}',
    'last_name': '{attributes[lname_test][0]}',
    'email' : '{attributes[email_test][0]}',
    'password' : '{attributes[password_test][0]}',
    'ep_principal_name' : '{attributes[ep_principal_name][0]}',
    's_etablissement' : '{attributes[s_etablissement][0]}',
    'ep_primary_affiliation' : '{attributes[ep_primary_affiliation][0]}',
    'ep_affiliation' : '{attributes[ep_affiliation][0]}',
    's_entite_affectation_principale' : '{attributes[s_entite_affectation_principale][0]}',
    's_entite_affectation' : '{attributes[s_entite_affectation][0]}',
    's_emp_corps' : '{attributes[s_emp_corps][0]}',
    's_liste_rouge' : '{attributes[s_liste_rouge][0]}',
}

MELLON_SUPERUSER_MAPPING = {
    'is_superuser': 'true',
}

MELLON_USERNAME_TEMPLATE = '{attributes[name_id_content]}'

MELLON_IDENTITY_PROVIDERS = [{
    'METADATA_URL': 'http://idp-condorcet.dev.entrouvert.org/idp/saml2/metadata'
}]

MELLON_DISCOVERY_SERVICE_URL = "https://discovery.renater.fr/test"

MELLON_PUBLIC_KEYS = ('''MIIC+TCCAeGgAwIBAgIJAPDzLp0rbCqRMA0GCSqGSIb3DQEBCwUAMBMxETAPBgNV
BAMMCHdob2NhcmVzMB4XDTE3MDMwODE2MjYyNloXDTI3MDMwNjE2MjYyNlowEzER
MA8GA1UEAwwId2hvY2FyZXMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
AQDEgvuUDz+6Gsn/DGwWn2rfkGdCBXIvJzCD7zpHIX2rZGZMcbo6SoDW+NG/N+D0
27j4/A+9LgXaIDMZaUx0ICtu5vzqQMLjKhmhq8HyA9yfvGtexxETyli5YkM0B4Q8
uO2NMlGX9zQKjox7ebjJhF0PCPmRaq9ZGJSJFS8ywU3prqm2RORUkwBeGL7oJPoz
WTb/1kU4qPXBXeiMaL/3xzVi9VrJSNs69oOIKvnfLX+i8hZZL8qPtfMhycv9E12M
BI/qKxS3fqCcVb+GKNl1DwivSz2bkzu1a5azrm9JmjxAxh1cv5yWJjotmFkjCbad
Q/gSgdcN22Fi53jv3LXpw+PZAgMBAAGjUDBOMB0GA1UdDgQWBBQyz+pQ7a1q0viR
oGrFnu2VJzzy2DAfBgNVHSMEGDAWgBQyz+pQ7a1q0viRoGrFnu2VJzzy2DAMBgNV
HRMEBTADAQH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umbAyHXuJWEM1JHSdICoVkQasZwMJ
VY1yhj9MnYlHZRTwuB0LvgU5Eqf0ZLFKzoNn1DjMwQKBgQDp7MZrfW29qHb7Pc6m
O5NjQe6VlMx/0a//2O2NrBiSqALNyPpAqTz9eML9w35kUqnbTEkikCZsV9PG/Uxg
WDZ4JHJE3M/gn/dOGb2wQMkzVlqKEJL70T3/Y98ucjJVczdEKOivRq6cQXb+g1uG
NxVos1ts0meMNFVPVm+w3SNLTwKBgQDXDl4aQcybKtLCguGPXApGoImN3gJhTvKR
9eck2wqLJGIvdwSOzLZq95q7iGUsY3EMQ6PbweZWiI3tM1hD4CM3AymooeyoeAJF
Q9ozIRKu8YjV3DopCWgYRp7QvE8nHqOyQFbsUpX39kRqwZHPcYdx7SVBti9EGJ45
qMNfWaL0VwKBgQDOq1ceboF/N5BvJkslyKrN3dlZJE6MewjAxLoUGcDYCUH456BZ
cmwlEQVNR+Op5PKWgk53D94yiGHdg7pvwF/XQ3QFbQTn0syentVdG8/m4Fs7cas6
ecIJmgX7Nf9MSW/Bc1coTA1Glfv4nrtE1/O9PgD/IuFDGJVqc9ZX7vgYtwKBgQC8
PyhiRYyrmr2oZFa7Xa7lCeu+kkJ1GV0+JQky+sXs7GlB8SW9NjbLxXfdhlRBmb5A
JQlO+Rj+UEQkCRjPOWi54/vYT/1PrtUV+oIK1X18Q5Mq2L7UYxaKgW7NeriynqBe
DPHJpbT+u8RByrUu58rPD+3X6njPW9lM0YxLb7QzuwKBgHMJZvc5YUJ6/TXrsoVg
MnwMlHDoIsUWFdWO4O5WaHszgA4ST0S2NWvLq+7dVREPMCpIjoZrGcXZlVxTiTbE
wMXFR0bCFblwVciyltVp5YyvMy+yBPW+8xAQ4hCHXeWGbV2iNYEsEHoiGSBfVmCM
JT6ZsP4RglqmN7XNUebJ/ogN'''

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'saml',
    'invite',
    'mellon',
    'gadjo',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.locale.LocaleMiddleware',
)

ROOT_URLCONF = 'sp_sso.urls'

WSGI_APPLICATION = 'sp_sso.wsgi.application'

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

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

SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = False

USE_TZ = True

LANGUAGES = (
    ('fr', _('French')),
    ('en', _('English')),
)

LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale_dir/'),
)

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

STATIC_URL = '/static/'
STATIC_ROOT = 'collected_static'

STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
STATICFILES_FINDERS = global_settings.STATICFILES_FINDERS + ('gadjo.finders.XStaticFinder',)

SESSION_EXPIRE_AT_BROWSER_CLOSE = False
SESSION_COOKIE_AGE = 30 * 60
