"""
Django settings for webdevtest project.

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

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

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

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

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/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'u(@8+j6p9e8_vtc!s!(awlkt827cof%#a9y*9+lc*%(vn$qhq='

# 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',
    'social_auth',
    'social_auth_widget',
    'myapp',
)

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.security.SecurityMiddleware',
)

ROOT_URLCONF = 'webdevtest.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = 'webdevtest.wsgi.application'


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

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


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

LANGUAGE_CODE = 'ru-RU'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.request',
    'social_auth.context_processors.social_auth_by_name_backends',
)

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.twitter.TwitterBackend',
    'social_auth.backends.facebook.FacebookBackend',
    'social_auth.backends.contrib.vk.VKOAuth2Backend',
    'social_auth.backends.google.GoogleOAuth2Backend',
    'social_auth.backends.contrib.github.GithubBackend',
    'social_auth.backends.contrib.odnoklassniki.OdnoklassnikiBackend',
    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_DEFAULT_USERNAME = lambda: random.choice(['Darth_Vader', 'Obi-Wan_Kenobi', 'R2-D2', 'C-3PO', 'Yoda'])

SOCIAL_AUTH_CREATE_USERS = True


SOCIAL_AUTH_PIPELINE = (
    'social_auth.backends.pipeline.social.social_auth_user',
    'social_auth.backends.pipeline.associate.associate_by_email',
    'social_auth.backends.pipeline.user.get_username',
    'social_auth.backends.pipeline.user.create_user',
    'social_auth.backends.pipeline.social.associate_user',
    'social_auth.backends.pipeline.social.load_extra_data',
    'social_auth.backends.pipeline.user.update_user_details'
)

SOCIAL_AUTH_PROVIDERS = [
    {'id': p[0], 'name': p[1], 'position': {'width': p[2][0], 'height': p[2][1], }}
    for p in (
        ('facebook', u'Login with Facebook', (0, 0)),
        ('vk-oauth', u'Login with Vk', (0, -80)),
        # Google registration isn't working :(
        #('google-oauth2', u'Login via Google', (0, -160)),
        # I did twitter registration :)
        ('twitter', u'Login with Twitter', (0, -240)),
        # I tried to add 'ok' registration.
        #('odnoklassniki', u'Login via OK', (0, -320)),
    )
]

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

FACEBOOK_APP_ID = '627848597354421'
FACEBOOK_API_SECRET = 'bf9a0666fa5228edabd4491028ca5d3d'

VK_APP_ID = '5318699'
VKONTAKTE_APP_ID = VK_APP_ID
VK_API_SECRET = 'EIMfxk7qHSZoR8TdzBuf'
VKONTAKTE_APP_SECRET = VK_API_SECRET

GOOGLE_OAUTH2_CLIENT_ID = '609339046437-bkjop9861dtrqrkd42eijo1bdifap20g.apps.googleusercontent.com'
GOOGLE_OAUTH2_CLIENT_SECRET = '1T0YBtjiJ57f0Y-pwn7W-nF0'

TWITTER_CONSUMER_KEY = 'zbKRyAGvxFNWXMgB5tlMS6xXM'
TWITTER_CONSUMER_SECRET = 'ycIB0aUkGarBPJ6s5r1V2MtUyc3fkv9eNUp8znGkxugHQnm8Cl'

ODNOKLASSNIKI_OAUTH2_CLIENT_KEY = '1246266880'
ODNOKLASSNIKI_OAUTH2_APP_KEY = 'CBAHIJELEBABABABA'
ODNOKLASSNIKI_OAUTH2_CLIENT_SECRET = '581EB272E0CEAC11B985CCDF'