<gh_stars>0
"""
Django settings for sms_verifier project.

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

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

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

import os
import socket

ENVIRONMENT = os.environ.get('environment', 'dev')
DOMAIN_NAME = os.environ.get('domain_name', 'http://127.0.0.1:8000')

try:
    HOSTNAME = socket.gethostname()
except ImportError as e:
    HOSTNAME = 'localhost'
PROJECT_NAME = 'SMS Verifier'
VERSION = os.environ.get('version', 'null')

EXTRA_ALLOWED_HOSTS = os.environ.get('allowed_hosts', '').split(',')

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('django_secret_key', 'djangoSecretKey')

# SECURITY WARNING: don't run with debug turned on in production!
if ENVIRONMENT == 'dev' or ENVIRONMENT == 'ci':
    DEBUG = True
    EXTRA_ALLOWED_HOSTS.append('*')
else:
    DEBUG = False

INTERNAL_IPS = [
    '127.0.0.1',
]

ALLOWED_HOSTS = [
    'alpha.sms-verifier.nalkins.cloud',
    'sms-verifier.nalkins.cloud',
    '127.0.0.1',
    '10.0.2.2',  # Android AVD IP for localhost
] + EXTRA_ALLOWED_HOSTS

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'rest_framework',
    'oauth2_provider',
    'django_user_email_extension',

    'sms_verifier_app'
]

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 = 'sms_verifier.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 = 'sms_verifier.wsgi.application'

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

######################
# DATABASE SETTINGS
######################
if ENVIRONMENT == 'dev':
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': os.environ.get('db_name', 'sms_verifier'),
            'USER': os.environ.get('db_user', 'sms_verifier'),
            'PASSWORD': os.environ.get('db_pass', '<PASSWORD>'),
            'HOST': os.environ.get('db_host', 'localhost'),
            'PORT': '3306',
        }
    }

# Password validation
# https://docs.djangoproject.com/en/2.2/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/2.2/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/2.2/howto/static-files/

STATIC_URL = os.environ.get('static_url', "/static/")

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

######################
# Custom User Model
######################
AUTH_USER_MODEL = 'django_user_email_extension.User'

##################
# REST Framework
##################
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
        # 'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
}

######################
# Social Auth
######################
SOCIAL_AUTH_USER_MODEL = 'django_user_email_extension.User'

SOCIAL_AUTH_LOGIN_REDIRECT_URL = 'index'
SOCIAL_AUTH_LOGOUT_REDIRECT_URL = '/'
SOCIAL_AUTH_LOGIN_ERROR_URL = '/'
SOCIAL_AUTH_LOGIN_URL = 'index'
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.auth_allowed',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.social_auth.associate_by_email',
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
)

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = os.environ.get('google_oauth_client_id', 'None')
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = os.environ.get('google_oauth_client_secret', 'None')
SOCIAL_AUTH_GITHUB_KEY = os.environ.get('github_oauth_client_id', 'None')
SOCIAL_AUTH_GITHUB_SECRET = os.environ.get('github_oauth_client_secret', 'None')
SOCIAL_AUTH_GITHUB_SCOPE = [
    'read:user',
    'user:email',
    'read:org',
]

AUTHENTICATION_BACKENDS = (
    'social_core.backends.github.GithubOAuth2',
    'social_core.backends.google.GoogleOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

######################
# LOGGING SETTINGS
######################
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO')
HANDLERS = ['console']
LOGGING = {
    'version': 1,
    'handlers': {
        'console': {
            'level': LOG_LEVEL,
            'class': 'logging.StreamHandler',
        },
    },

    'loggers': {
        PROJECT_NAME: {
            'handlers': HANDLERS,
            'level': LOG_LEVEL,
        },
        'django.request': {
            'handlers': HANDLERS,
            'level': 'WARNING',
            'propagate': False,
        },
    },
}

"""
Django settings for sms_verifier project.

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

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

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

import os
import socket

ENVIRONMENT = os.environ.get('environment', 'dev')
DOMAIN_NAME = os.environ.get('domain_name', 'http://127.0.0.1:8000')

try:
    HOSTNAME = socket.gethostname()
except ImportError as e:
    HOSTNAME = 'localhost'
PROJECT_NAME = 'SMS Verifier'
VERSION = os.environ.get('version', 'null')

EXTRA_ALLOWED_HOSTS = os.environ.get('allowed_hosts', '').split(',')

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('django_secret_key', 'djangoSecretKey')

# SECURITY WARNING: don't run with debug turned on in production!
if ENVIRONMENT == 'dev' or ENVIRONMENT == 'ci':
    DEBUG = True
    EXTRA_ALLOWED_HOSTS.append('*')
else:
    DEBUG = False

INTERNAL_IPS = [
    '127.0.0.1',
]

ALLOWED_HOSTS = [
    'alpha.sms-verifier.nalkins.cloud',
    'sms-verifier.nalkins.cloud',
    '127.0.0.1',
    '10.0.2.2',  # Android AVD IP for localhost
] + EXTRA_ALLOWED_HOSTS

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'rest_framework',
    'oauth2_provider',
    'django_user_email_extension',

    'sms_verifier_app'
]

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 = 'sms_verifier.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 = 'sms_verifier.wsgi.application'

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

######################
# DATABASE SETTINGS
######################
if ENVIRONMENT == 'dev':
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': os.environ.get('db_name', 'sms_verifier'),
            'USER': os.environ.get('db_user', 'sms_verifier'),
            'PASSWORD': os.environ.get('db_pass', '<PASSWORD>'),
            'HOST': os.environ.get('db_host', 'localhost'),
            'PORT': '3306',
        }
    }

# Password validation
# https://docs.djangoproject.com/en/2.2/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/2.2/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/2.2/howto/static-files/

STATIC_URL = os.environ.get('static_url', "/static/")

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

######################
# Custom User Model
######################
AUTH_USER_MODEL = 'django_user_email_extension.User'

##################
# REST Framework
##################
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
        # 'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
}

######################
# Social Auth
######################
SOCIAL_AUTH_USER_MODEL = 'django_user_email_extension.User'

SOCIAL_AUTH_LOGIN_REDIRECT_URL = 'index'
SOCIAL_AUTH_LOGOUT_REDIRECT_URL = '/'
SOCIAL_AUTH_LOGIN_ERROR_URL = '/'
SOCIAL_AUTH_LOGIN_URL = 'index'
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.auth_allowed',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.social_auth.associate_by_email',
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
)

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = os.environ.get('google_oauth_client_id', 'None')
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = os.environ.get('google_oauth_client_secret', 'None')
SOCIAL_AUTH_GITHUB_KEY = os.environ.get('github_oauth_client_id', 'None')
SOCIAL_AUTH_GITHUB_SECRET = os.environ.get('github_oauth_client_secret', 'None')
SOCIAL_AUTH_GITHUB_SCOPE = [
    'read:user',
    'user:email',
    'read:org',
]

AUTHENTICATION_BACKENDS = (
    'social_core.backends.github.GithubOAuth2',
    'social_core.backends.google.GoogleOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

######################
# LOGGING SETTINGS
######################
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO')
HANDLERS = ['console']
LOGGING = {
    'version': 1,
    'handlers': {
        'console': {
            'level': LOG_LEVEL,
            'class': 'logging.StreamHandler',
        },
    },

    'loggers': {
        PROJECT_NAME: {
            'handlers': HANDLERS,
            'level': LOG_LEVEL,
        },
        'django.request': {
            'handlers': HANDLERS,
            'level': 'WARNING',
            'propagate': False,
        },
    },
}
Django settings for sms_verifier project.  Generated by 'django-admin startproject' using Django 2.2.6.  For more information on this file, see https://docs.djangoproject.com/en/2.2/topics/settings/  For the full list of settings and their values, see https://docs.djangoproject.com/en/2.2/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: don't run with debug turned on in production! # Android AVD IP for localhost # Application definition # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases ###################### # DATABASE SETTINGS ###################### # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ ###################### # Custom User Model ###################### ################## # REST Framework ################## # 'rest_framework.authentication.BasicAuthentication', ###################### # Social Auth ###################### ###################### # LOGGING SETTINGS ######################