diff --git a/.gitignore b/.gitignore index e30ea7f..61c06c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,10 @@ -# Created by https://www.toptal.com/developers/gitignore/api/django -# Edit at https://www.toptal.com/developers/gitignore?templates=django + +*.iml +.idea/inspectionProfiles/profiles_settings.xml +.idea/.gitignore +.idea/misc.xml +.idea/vcs.xml + ### Django ### *.log @@ -149,4 +154,196 @@ dmypy.json # profiling data .prof -# End of https://www.toptal.com/developers/gitignore/api/django \ No newline at end of file +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### PyCharm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### PyCharm Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + + *.iml + modules.xml + .idea/misc.xml + *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + + +# C extensions + +# Distribution / packaging + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. + +# Installer logs + +# Unit test / coverage reports + +# Translations + +# Django stuff: + +# Flask stuff: + +# Scrapy stuff: + +# Sphinx documentation + +# PyBuilder + +# Jupyter Notebook + +# IPython + +# pyenv + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow + +# Celery stuff + +# SageMath parsed files + +# Environments + +# Spyder project settings + +# Rope project settings + +# mkdocs documentation + +# mypy + +# Pyre type checker + +# pytype static type analyzer + +# profiling data + +# End of https://www.toptal.com/developers/gitignore/api/macos,pycharm,django,python + diff --git a/Model_Diagram.jpeg b/Model_Diagram.jpeg deleted file mode 100644 index 0482015..0000000 Binary files a/Model_Diagram.jpeg and /dev/null differ diff --git a/clone_linkedin/accounts/__init__.py b/clone_linkedin/accounts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/clone_linkedin/accounts/admin.py b/clone_linkedin/accounts/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/clone_linkedin/accounts/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/clone_linkedin/accounts/apps.py b/clone_linkedin/accounts/apps.py new file mode 100644 index 0000000..9b3fc5a --- /dev/null +++ b/clone_linkedin/accounts/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class AccountsConfig(AppConfig): + name = 'accounts' diff --git a/clone_linkedin/accounts/migrations/__init__.py b/clone_linkedin/accounts/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/clone_linkedin/accounts/models.py b/clone_linkedin/accounts/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/clone_linkedin/accounts/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/clone_linkedin/accounts/tests.py b/clone_linkedin/accounts/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/clone_linkedin/accounts/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/clone_linkedin/accounts/urls.py b/clone_linkedin/accounts/urls.py new file mode 100644 index 0000000..29db1c7 --- /dev/null +++ b/clone_linkedin/accounts/urls.py @@ -0,0 +1,12 @@ +from django.urls import path +from accounts.views import GoogleLogin + +app_name = 'accounts' +urlpatterns = [ + + path( + "login/google/", + GoogleLogin.as_view(), + name="google_login" + ), +] \ No newline at end of file diff --git a/clone_linkedin/accounts/views.py b/clone_linkedin/accounts/views.py new file mode 100644 index 0000000..8b138f9 --- /dev/null +++ b/clone_linkedin/accounts/views.py @@ -0,0 +1,7 @@ +from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter +from allauth.socialaccount.providers.oauth2.client import OAuth2Client +from rest_auth.registration.views import SocialLoginView + +class GoogleLogin(SocialLoginView): + adapter_class = GoogleOAuth2Adapter + client_class = OAuth2Client diff --git a/clone_linkedin/clone_linkedin/settings.py b/clone_linkedin/clone_linkedin/settings.py index 56147b6..759343d 100644 --- a/clone_linkedin/clone_linkedin/settings.py +++ b/clone_linkedin/clone_linkedin/settings.py @@ -42,8 +42,28 @@ 'rest_framework.authtoken', 'post.apps.PostConfig', 'user.apps.UserConfig', + 'accounts.apps.AccountsConfig', + 'django.contrib.sites', + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + 'allauth.socialaccount.providers.google', + 'rest_auth', + 'rest_auth.registration', ] +SOCIALACCOUNT_PROVIDERS = { + 'google': { + 'SCOPE': [ + 'profile', + 'email', + ], + 'AUTH_PARAMS': { + 'access_type': 'online', + } + } +} + MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -56,12 +76,16 @@ REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( - 'rest_framework.authentication.TokenAuthentication', + #'rest_framework.authentication.TokenAuthentication', + 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', ), 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', 'PAGE_SIZE': 5, } + +REST_USE_JWT = True + ROOT_URLCONF = 'clone_linkedin.urls' TEMPLATES = [ @@ -80,8 +104,20 @@ }, ] +SITE_ID = 1 + +LOGIN_REDIRECT_URL = '/posts/' # 로그인 후 돌아올 URL +ACCOUNT_LOGOUT_REDIRECT_URL = '/accounts/login/' +ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = False +SOCIALACCOUNT_STORE_TOKENS =True + WSGI_APPLICATION = 'clone_linkedin.wsgi.application' +AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'allauth.account.auth_backends.AuthenticationBackend', +) + # Database # https://docs.djangoproject.com/en/3.1/ref/settings/#databases diff --git a/clone_linkedin/clone_linkedin/urls.py b/clone_linkedin/clone_linkedin/urls.py index ec62b82..1d7eeca 100644 --- a/clone_linkedin/clone_linkedin/urls.py +++ b/clone_linkedin/clone_linkedin/urls.py @@ -1,3 +1,4 @@ + """clone_linkedin URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: @@ -13,6 +14,7 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from django.conf import settings from django.conf.urls import url from django.contrib import admin @@ -21,4 +23,8 @@ urlpatterns = [ path('admin/', admin.site.urls), path('', include('post.urls')), + path('accounts/', include('accounts.urls')), + path('accounts/', include('allauth.urls')), + url(r'^rest-auth/', include('rest_auth.urls')), + url(r'^rest-auth/registration/', include('rest_auth.registration.urls')), ] diff --git a/requirements.txt b/requirements.txt index 524f5b6..85ee5b5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,7 @@ django-debug-toolbar==2.2 djangorestframework==3.11.1 mysqlclient==2.0.1 pytz==2020.1 -sqlparse==0.3.1 \ No newline at end of file +sqlparse==0.3.1 +django-allauth==0.44.0 +django-rest-auth==0.9.5 +djangorestframework-jwt==1.11.0