super basic working example

This commit is contained in:
vabene1111 2021-01-21 20:54:55 +01:00
parent 6992bf83aa
commit 098f88e0b8
7 changed files with 22 additions and 12 deletions

View File

@ -152,7 +152,7 @@ class OwnerRequiredMixin(object):
_('You are not logged in and therefore cannot view this page!') _('You are not logged in and therefore cannot view this page!')
) )
return HttpResponseRedirect( return HttpResponseRedirect(
reverse_lazy('login') + '?next=' + request.path reverse_lazy('account_login') + '?next=' + request.path
) )
else: else:
if not is_object_owner(request.user, self.get_object()): if not is_object_owner(request.user, self.get_object()):

View File

@ -149,13 +149,13 @@
<a class="dropdown-item" href="{% url 'api:api-root' %}"><i <a class="dropdown-item" href="{% url 'api:api-root' %}"><i
class="fas fa-file-code fa-fw"></i> {% trans 'API Browser' %}</a> class="fas fa-file-code fa-fw"></i> {% trans 'API Browser' %}</a>
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<a class="dropdown-item" href="{% url 'logout' %}"><i <a class="dropdown-item" href="{% url 'account_logout' %}"><i
class="fas fa-sign-out-alt fa-fw"></i> {% trans 'Logout' %}</a> class="fas fa-sign-out-alt fa-fw"></i> {% trans 'Logout' %}</a>
</div> </div>
</li> </li>
{% else %} {% else %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'login' %}">{% trans 'Login' %} <i class="fas fa-sign-in-alt"></i></a> <a class="nav-link" href="{% url 'account_logout' %}">{% trans 'Login' %} <i class="fas fa-sign-in-alt"></i></a>
</li> </li>
{% endif %} {% endif %}
</ul> </ul>

View File

@ -13,7 +13,7 @@
{% endif %} {% endif %}
<form role="form" class="form-horizontal" method="post" action="{% url 'login' %}"> <form role="form" class="form-horizontal" method="post" action="{% url 'account_login' %}">
{% csrf_token %} {% csrf_token %}
<div class="form-group"> <div class="form-group">

View File

@ -48,7 +48,7 @@ def index(request):
page_map.get(request.user.userpreference.default_page) page_map.get(request.user.userpreference.default_page)
) )
except UserPreference.DoesNotExist: except UserPreference.DoesNotExist:
return HttpResponseRedirect(reverse('login') + '?next=' + request.path) return HttpResponseRedirect(reverse('account_login') + '?next=' + request.path)
def search(request): def search(request):
@ -87,7 +87,7 @@ def search(request):
{'recipes': table, 'filter': f, 'last_viewed': last_viewed} {'recipes': table, 'filter': f, 'last_viewed': last_viewed}
) )
else: else:
return HttpResponseRedirect(reverse('login') + '?next=' + request.path) return HttpResponseRedirect(reverse('account_login') + '?next=' + request.path)
def recipe_view(request, pk, share=None): def recipe_view(request, pk, share=None):
@ -99,7 +99,7 @@ def recipe_view(request, pk, share=None):
messages.ERROR, messages.ERROR,
_('You do not have the required permissions to view this page!') _('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) comments = Comment.objects.filter(recipe=recipe)
@ -377,7 +377,7 @@ def setup(request):
messages.ERROR, 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 _('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': if request.method == 'POST':
form = UserCreateForm(request.POST) form = UserCreateForm(request.POST)
@ -399,7 +399,7 @@ def setup(request):
messages.SUCCESS, messages.SUCCESS,
_('User has been created, please login!') _('User has been created, please login!')
) )
return HttpResponseRedirect(reverse('login')) return HttpResponseRedirect(reverse('account_login'))
except ValidationError as e: except ValidationError as e:
for m in e: for m in e:
form.add_error('password', m) form.add_error('password', m)
@ -450,7 +450,7 @@ def signup(request, token):
link.used_by = user link.used_by = user
link.save() link.save()
user.groups.add(link.group) user.groups.add(link.group)
return HttpResponseRedirect(reverse('login')) return HttpResponseRedirect(reverse('account_login'))
except ValidationError as e: except ValidationError as e:
for m in e: for m in e:
form.add_error('password', m) form.add_error('password', m)

View File

@ -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'] 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 # allow djangos wsgi server to server mediafiles
GUNICORN_MEDIA = bool(int(os.getenv('GUNICORN_MEDIA', True))) GUNICORN_MEDIA = bool(int(os.getenv('GUNICORN_MEDIA', True)))
@ -68,6 +71,7 @@ INSTALLED_APPS = [
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.sites',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django_tables2', 'django_tables2',
'django_filters', 'django_filters',
@ -78,6 +82,10 @@ INSTALLED_APPS = [
'django_cleanup.apps.CleanupConfig', 'django_cleanup.apps.CleanupConfig',
'webpack_loader', 'webpack_loader',
'django_js_reverse', 'django_js_reverse',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.github',
'cookbook.apps.CookbookConfig', 'cookbook.apps.CookbookConfig',
] ]
@ -95,6 +103,7 @@ MIDDLEWARE = [
AUTHENTICATION_BACKENDS = [ AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend', 'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
] ]
if REVERSE_PROXY_AUTH: if REVERSE_PROXY_AUTH:

View File

@ -25,7 +25,7 @@ from django_js_reverse import views as reverse_views
urlpatterns = [ urlpatterns = [
path('', include('cookbook.urls')), path('', include('cookbook.urls')),
path('admin/', admin.site.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('i18n/', include('django.conf.urls.i18n')),
path( path(
'jsi18n/', 'jsi18n/',

View File

@ -31,3 +31,4 @@ Jinja2==2.11.2
django-webpack-loader==0.7.0 django-webpack-loader==0.7.0
django-js-reverse==0.9.1 django-js-reverse==0.9.1
pre-commit==2.9.3 pre-commit==2.9.3
django-allauth==0.44.0