# django-social-auth (https://github.com/omab/django-social-auth) provides user registration
# and login with credentials from various social sites and authentication methods. Transifex
# supports Twitter, Facebook and Google logins based on the OAuth protocol.
#
# For more information, see https://github.com/omab/django-social-auth/blob/master/README.rst
#
# OAuth keys need to be issued for all three services from the corresponding service
# websites.
#
# Twitter
# -------
# Twitter offers per application keys named Consumer Key and Consumer Secret. To enable
# Twitter logins these two keys are needed.
#
#     - Create a new application at https://dev.twitter.com/apps/new
#     - Twitter won't allow you to use local addresses for the website and callback URL
#       during development so you can either create a bit.ly URL that resolves to localhost
#       or put a fake domain in your hosts file (or use something like dnsmasq).
#     - The callback URL should be http://<hostname>/accounts/complete/twitter.
#     - Put the Consumer key/secret values in the settings below.
#
# Facebook
# --------
# Facebook works similar to Twitter.
#
#     - Register a new application at http://developers.facebook.com/setup/
#     - Fill App Id and App Secret values in the settings below:
#       FACEBOOK_APP_ID
#       FACEBOOK_API_SECRET
#     - Again, you can't use local addresses as the redirect URL.
#     - The callback URL should be http://<hostname>/accounts/complete/facebook
#
#
# Google OAuth2
# -------------
# To enable Google OAuth2 support you have to register your application and apply
# for a set of keys.
#
#     - To register your application, go to http://code.google.com/apis/console
#     create a project in the APIs Console, then click the "Create an OAuth 2.0 client ID"
#     button in the API Access tab and fill in the details.
#
#     - During development, you can use 'localhost' or '127.0.0.1' as the hostname.
#
#     - The redirect URI should be:
#
#         http://<hostname>/accounts/complete/google-oauth2/
#
#     - Use the Client ID and Client secret values in the settings below.
#
#
# LinkedIn
# --------
# The process is similar to the other OAuth providers.
#
#     - Register an application at https://www.linkedin.com/secure/developer
#       and use the API Key and Secret Key in the settings below.
#

# Enable/Disable social authentication for the whole site
USE_SOCIAL_LOGIN = True

# Enabled backends
SOCIAL_AUTH_ENABLED_BACKENDS = ('twitter', 'google-oauth2', 'facebook', 'linkedin')

# This can be used to add custom authentication backends living
# outside the django-social-auth app.
SOCIAL_AUTH_IMPORT_BACKENDS = ()

LOGIN_ERROR_URL = '/profile/social'
SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL = '/profile/social'
SOCIAL_AUTH_DISCONNECT_REDIRECT_URL = '/profile/social'

# See above for instructions on how to setup these.
TWITTER_CONSUMER_KEY         = ''
TWITTER_CONSUMER_SECRET      = ''
FACEBOOK_APP_ID              = ''
FACEBOOK_API_SECRET          = ''
GOOGLE_OAUTH2_CLIENT_KEY     = ''
GOOGLE_OAUTH2_CLIENT_SECRET  = ''
GOOGLE_DISPLAY_NAME          = 'Transifex'
LINKEDIN_CONSUMER_KEY        = ''
LINKEDIN_CONSUMER_SECRET     = ''

# Used to fill in the linked_in field of the profile
LINKEDIN_EXTRA_FIELD_SELECTORS = ['public-profile-url',]

# Used to purify usernames
from txcommon.template import slugify
SOCIAL_AUTH_USERNAME_FIXER = lambda u: slugify(u).replace('-', '.')


# Register our custom user creation function
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',
    'transifex.txcommon.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',
)
