From 08ac278a9a37d4f4263e9d3dc8bd22defcb83807 Mon Sep 17 00:00:00 2001 From: DJ Gillespie Date: Thu, 13 Aug 2020 19:33:57 -0600 Subject: [PATCH] [QRTR-76] User creation added. --- core/settings.py | 5 +- core/settings/__init__.py | 137 ++++++++++++++++++++++++++++++++++++++ core/settings/local.py | 18 +++++ core/urls.py | 10 ++- qrtr_account/views.py | 13 ++++ requirements.txt | 3 +- 6 files changed, 177 insertions(+), 9 deletions(-) create mode 100644 core/settings/__init__.py create mode 100644 core/settings/local.py diff --git a/core/settings.py b/core/settings.py index 98f82dd..ad4c0a7 100644 --- a/core/settings.py +++ b/core/settings.py @@ -43,11 +43,8 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'rest_framework', 'rest_framework.authtoken', - 'rest_auth', + 'dj_rest_auth', 'django.contrib.sites', - 'allauth', - 'allauth.account', - 'rest_auth.registration', 'api', 'user', 'connection', diff --git a/core/settings/__init__.py b/core/settings/__init__.py new file mode 100644 index 0000000..6e3f0e3 --- /dev/null +++ b/core/settings/__init__.py @@ -0,0 +1,137 @@ +""" +Django settings for qrtr_services 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 + +try: + from .local import * +except ImportError: + print("Loading Production Environment!") + from .production import * + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'rest_framework', + 'rest_framework.authtoken', + 'dj_rest_auth', + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + 'dj_rest_auth.registration', + 'allauth.socialaccount.providers.facebook', + 'allauth.socialaccount.providers.twitter', + 'django.contrib.sites', + 'api', + 'user', + 'connection', + 'qrtr_account', + 'corsheaders', +] + +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + +SITE_ID = 1 + + +MIDDLEWARE = [ + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.common.CommonMiddleware', + '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', + 'whitenoise.middleware.WhiteNoiseMiddleware', +] + +CORS_ORIGIN_WHITELIST = [ + 'http://localhost:3000', + 'https://localhost:3000' +] + +ROOT_URLCONF = 'core.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 = 'core.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + + + +AUTH_USER_MODEL = 'user.User' + +# 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 = False + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.2/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/core/settings/local.py b/core/settings/local.py new file mode 100644 index 0000000..ca60fe4 --- /dev/null +++ b/core/settings/local.py @@ -0,0 +1,18 @@ +import os +import dj_database_url + + +DEFAULT_CONNECTION = dj_database_url.parse('postgres://djg:1774274aB@localhost:5432/qrtr-local') + +DATABASES = {"default": DEFAULT_CONNECTION, } + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'jc@r$_x4$mp-b84&+m3s@hm7kpl$br-wa&50*&xjx^^fddg6q$' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = ['*'] \ No newline at end of file diff --git a/core/urls.py b/core/urls.py index a9ed67f..9549819 100644 --- a/core/urls.py +++ b/core/urls.py @@ -25,7 +25,9 @@ from qrtr_account.views import (AccountViewSet, TransactionViewSet, SliceViewSet, ConnectionViewSet, - ConnectionTypeViewSet) + ConnectionTypeViewSet, + FacebookLogin, + TwitterLogin) router = routers.DefaultRouter() @@ -44,8 +46,10 @@ router.register(r'connectiontypes',ConnectionTypeViewSet) apipatterns = [ path('', include(router.urls)), - path('auth/', include('rest_framework.urls', namespace='rest_framework'), name='auth'), - path('auth/registration/', include('rest_auth.registration.urls'), name='register'), + path('auth/', include('dj_rest_auth.urls'), name='auth'), + path('auth/registration/', include('dj_rest_auth.registration.urls')), + path('auth/facebook/', FacebookLogin.as_view(), name='fb_login'), + path('auth/twitter/', TwitterLogin.as_view(), name='twitter_login'), path('connection/', include('connection.urls'), name='Connection Settings'), ] diff --git a/qrtr_account/views.py b/qrtr_account/views.py index 9459bd2..6f0eaec 100644 --- a/qrtr_account/views.py +++ b/qrtr_account/views.py @@ -10,6 +10,19 @@ from api.serializers import (AccountSerializer, ConnectionTypeSerializer, SliceSerializer, RuleSerializer) +from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter +from dj_rest_auth.registration.views import SocialLoginView +from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter +from dj_rest_auth.social_serializers import TwitterLoginSerializer + + +class TwitterLogin(SocialLoginView): + serializer_class = TwitterLoginSerializer + adapter_class = TwitterOAuthAdapter + + +class FacebookLogin(SocialLoginView): + adapter_class = FacebookOAuth2Adapter class AccountViewSet(viewsets.ModelViewSet): diff --git a/requirements.txt b/requirements.txt index 47b1e23..2c49ac0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,10 @@ Django>=3.0.5 -django-allauth>=0.40.0 django-cors-headers>=3.2.0 django-genericrelationview>=0.1.1 django-jsonfield>=1.3.1 -django-rest-auth>=0.9.5 django-rest-framework>=0.1.0 djangorestframework>=3.10.3 +dj-rest-auth>=1.1.0 ipykernel>=5.1.2 ipython>=5.8.0 plaid-python>=3.7.0