From 098f88e0b81cd7c5d3ad0d671ddfe0654eff4c42 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Thu, 21 Jan 2021 20:54:55 +0100 Subject: [PATCH] super basic working example --- cookbook/helper/permission_helper.py | 2 +- cookbook/templates/base.html | 4 ++-- cookbook/templates/registration/login.html | 2 +- cookbook/views/views.py | 12 ++++++------ recipes/settings.py | 9 +++++++++ recipes/urls.py | 2 +- requirements.txt | 3 ++- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/cookbook/helper/permission_helper.py b/cookbook/helper/permission_helper.py index 1b71ab2b..7093ac77 100644 --- a/cookbook/helper/permission_helper.py +++ b/cookbook/helper/permission_helper.py @@ -152,7 +152,7 @@ class OwnerRequiredMixin(object): _('You are not logged in and therefore cannot view this page!') ) return HttpResponseRedirect( - reverse_lazy('login') + '?next=' + request.path + reverse_lazy('account_login') + '?next=' + request.path ) else: if not is_object_owner(request.user, self.get_object()): diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index d5303751..181dbd19 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -149,13 +149,13 @@ {% trans 'API Browser' %} - {% trans 'Logout' %} {% else %} {% endif %} diff --git a/cookbook/templates/registration/login.html b/cookbook/templates/registration/login.html index 5d90ebba..40b0497e 100644 --- a/cookbook/templates/registration/login.html +++ b/cookbook/templates/registration/login.html @@ -13,7 +13,7 @@ {% endif %} -
+ {% csrf_token %}
diff --git a/cookbook/views/views.py b/cookbook/views/views.py index 0900acb5..c22baa90 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -48,7 +48,7 @@ def index(request): page_map.get(request.user.userpreference.default_page) ) except UserPreference.DoesNotExist: - return HttpResponseRedirect(reverse('login') + '?next=' + request.path) + return HttpResponseRedirect(reverse('account_login') + '?next=' + request.path) def search(request): @@ -87,7 +87,7 @@ def search(request): {'recipes': table, 'filter': f, 'last_viewed': last_viewed} ) else: - return HttpResponseRedirect(reverse('login') + '?next=' + request.path) + return HttpResponseRedirect(reverse('account_login') + '?next=' + request.path) def recipe_view(request, pk, share=None): @@ -99,7 +99,7 @@ def recipe_view(request, pk, share=None): messages.ERROR, _('You do not have the required permissions to view this page!') ) - return HttpResponseRedirect(reverse('login') + '?next=' + request.path) + return HttpResponseRedirect(reverse('account_login') + '?next=' + request.path) comments = Comment.objects.filter(recipe=recipe) @@ -377,7 +377,7 @@ def setup(request): messages.ERROR, _('The setup page can only be used to create the first user! If you have forgotten your superuser credentials please consult the django documentation on how to reset passwords.') # noqa: E501 ) - return HttpResponseRedirect(reverse('login')) + return HttpResponseRedirect(reverse('account_login')) if request.method == 'POST': form = UserCreateForm(request.POST) @@ -399,7 +399,7 @@ def setup(request): messages.SUCCESS, _('User has been created, please login!') ) - return HttpResponseRedirect(reverse('login')) + return HttpResponseRedirect(reverse('account_login')) except ValidationError as e: for m in e: form.add_error('password', m) @@ -450,7 +450,7 @@ def signup(request, token): link.used_by = user link.save() user.groups.add(link.group) - return HttpResponseRedirect(reverse('login')) + return HttpResponseRedirect(reverse('account_login')) except ValidationError as e: for m in e: form.add_error('password', m) diff --git a/recipes/settings.py b/recipes/settings.py index a2e17752..bfda01d9 100644 --- a/recipes/settings.py +++ b/recipes/settings.py @@ -27,6 +27,9 @@ DEMO = bool(int(os.getenv('DEMO', False))) INTERNAL_IPS = os.getenv('INTERNAL_IPS').split(',') if os.getenv('INTERNAL_IPS') else ['127.0.0.1'] +# django allauth site id +SITE_ID = int(os.getenv('ALLAUTH_SITE_ID', 1)) + # allow djangos wsgi server to server mediafiles GUNICORN_MEDIA = bool(int(os.getenv('GUNICORN_MEDIA', True))) @@ -68,6 +71,7 @@ INSTALLED_APPS = [ 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', + 'django.contrib.sites', 'django.contrib.staticfiles', 'django_tables2', 'django_filters', @@ -78,6 +82,10 @@ INSTALLED_APPS = [ 'django_cleanup.apps.CleanupConfig', 'webpack_loader', 'django_js_reverse', + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + 'allauth.socialaccount.providers.github', 'cookbook.apps.CookbookConfig', ] @@ -95,6 +103,7 @@ MIDDLEWARE = [ AUTHENTICATION_BACKENDS = [ 'django.contrib.auth.backends.ModelBackend', + 'allauth.account.auth_backends.AuthenticationBackend', ] if REVERSE_PROXY_AUTH: diff --git a/recipes/urls.py b/recipes/urls.py index bc64f94a..0879fbcc 100644 --- a/recipes/urls.py +++ b/recipes/urls.py @@ -25,7 +25,7 @@ from django_js_reverse import views as reverse_views urlpatterns = [ path('', include('cookbook.urls')), path('admin/', admin.site.urls), - path('accounts/', include('django.contrib.auth.urls')), + path('accounts/', include('allauth.urls')), path('i18n/', include('django.conf.urls.i18n')), path( 'jsi18n/', diff --git a/requirements.txt b/requirements.txt index 717b43eb..92862d8a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,4 +30,5 @@ django-random-queryset==0.1.3 Jinja2==2.11.2 django-webpack-loader==0.7.0 django-js-reverse==0.9.1 -pre-commit==2.9.3 \ No newline at end of file +pre-commit==2.9.3 +django-allauth==0.44.0 \ No newline at end of file