diff --git a/backend/core/settings.py b/backend/core/settings.py index df9254b..9c0d203 100644 --- a/backend/core/settings.py +++ b/backend/core/settings.py @@ -30,6 +30,8 @@ ALLOWED_HOSTS = [] # Application definition +SITE_ID = 2 + INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', @@ -37,8 +39,24 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'users', + 'django.contrib.sites', + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + 'allauth.socialaccount.providers.google', ] +SOCIALACCOUNT_PROVIDERS = { + 'google' : { + 'SCOPE' : [ + 'profile', + 'email', + ], + 'AUTH_PARAMS' : {'access_type' : 'online'} + } +} + MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -47,6 +65,7 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + "allauth.account.middleware.AccountMiddleware", ] ROOT_URLCONF = 'core.urls' @@ -121,3 +140,11 @@ STATIC_URL = 'static/' # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'allauth.account.auth_backends.AuthenticationBackend', +) + +LOGIN_REDIRECT_URL = '/' +LOGOUT_REDIRECT_URL = '/' \ No newline at end of file diff --git a/backend/core/urls.py b/backend/core/urls.py index 3b2f61e..1e308bb 100644 --- a/backend/core/urls.py +++ b/backend/core/urls.py @@ -15,8 +15,10 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('accounts/', include('allauth.urls')), + path('', include('users.urls')), ] diff --git a/backend/users/__init__.py b/backend/users/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/users/admin.py b/backend/users/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/backend/users/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/backend/users/apps.py b/backend/users/apps.py new file mode 100644 index 0000000..72b1401 --- /dev/null +++ b/backend/users/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'users' diff --git a/backend/users/migrations/__init__.py b/backend/users/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/users/models.py b/backend/users/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/backend/users/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/backend/users/templates/users/home.html b/backend/users/templates/users/home.html new file mode 100644 index 0000000..f6a48ec --- /dev/null +++ b/backend/users/templates/users/home.html @@ -0,0 +1,14 @@ + + + + + + + Django Google Sign In + + + {% load socialaccount %} +

Google Login

+ Login With Google + + \ No newline at end of file diff --git a/backend/users/tests.py b/backend/users/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/backend/users/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/backend/users/urls.py b/backend/users/urls.py new file mode 100644 index 0000000..5fd6401 --- /dev/null +++ b/backend/users/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.home), + path('logout', views.logout_view), +] diff --git a/backend/users/views.py b/backend/users/views.py new file mode 100644 index 0000000..a5af2c8 --- /dev/null +++ b/backend/users/views.py @@ -0,0 +1,10 @@ +from django.shortcuts import render, redirect +from django.contrib.auth import logout + +def home(request): + return render(request, 'users/home.html') + + +def logout_view(request): + logout(request) + return redirect('/') \ No newline at end of file