allauth working and integrated
This commit is contained in:
parent
53c715b6f6
commit
63cfa14a21
@ -9,7 +9,11 @@ class AllAuthCustomAdapter(DefaultAccountAdapter):
|
||||
"""
|
||||
Whether to allow sign ups.
|
||||
"""
|
||||
allow_signups = super(
|
||||
AllAuthCustomAdapter, self).is_open_for_signup(request)
|
||||
# Override with setting, otherwise default to super.
|
||||
return getattr(settings, 'ACCOUNT_ALLOW_SIGNUPS', allow_signups)
|
||||
if request.resolver_match.view_name == 'account_signup':
|
||||
return False
|
||||
else:
|
||||
return super(AllAuthCustomAdapter, self).is_open_for_signup(request)
|
||||
|
||||
# disable password reset for now
|
||||
def send_mail(self, template_prefix, email, context):
|
||||
pass
|
||||
|
@ -119,7 +119,7 @@ def group_required(*groups_required):
|
||||
def in_groups(u):
|
||||
return has_group_permission(u, groups_required)
|
||||
|
||||
return user_passes_test(in_groups)
|
||||
return user_passes_test(in_groups, login_url='view_no_group')
|
||||
|
||||
|
||||
class GroupRequiredMixin(object):
|
||||
@ -138,8 +138,7 @@ class GroupRequiredMixin(object):
|
||||
)
|
||||
return HttpResponseRedirect(reverse_lazy('index'))
|
||||
|
||||
return super(GroupRequiredMixin, self) \
|
||||
.dispatch(request, *args, **kwargs)
|
||||
return super(GroupRequiredMixin, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
class OwnerRequiredMixin(object):
|
||||
|
56
cookbook/templates/account/login.html
Normal file
56
cookbook/templates/account/login.html
Normal file
@ -0,0 +1,56 @@
|
||||
{% extends "base.html" %}
|
||||
{% load crispy_forms_filters %}
|
||||
{% load i18n %}
|
||||
|
||||
{% load account socialaccount %}
|
||||
|
||||
{% block title %}{% trans 'Login' %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12" style="text-align: center">
|
||||
<h3>{% trans "Sign In" %}</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-6 offset-3">
|
||||
<form class="login" method="POST" action="{% url 'account_login' %}">
|
||||
{% csrf_token %}
|
||||
{{ form | crispy }}
|
||||
|
||||
{% if redirect_field_value %}
|
||||
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}"/>
|
||||
{% endif %}
|
||||
|
||||
<button class="btn btn-primary" type="submit">{% trans "Sign In" %}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% get_providers as socialaccount_providers %}
|
||||
|
||||
{% if socialaccount_providers %}
|
||||
<div class="row" style="margin-top: 2vh">
|
||||
<div class="col-6 offset-3">
|
||||
<h5>{% trans "Social Login" %}</h5>
|
||||
<span>{% trans 'You can use any of the following providers to sign in.' %}</span>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<ul class="socialaccount_providers">
|
||||
{% include "socialaccount/snippets/provider_list.html" with process="login" %}
|
||||
</ul>
|
||||
|
||||
|
||||
{% include "socialaccount/snippets/login_extra.html" %}
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% endblock %}
|
22
cookbook/templates/account/logout.html
Normal file
22
cookbook/templates/account/logout.html
Normal file
@ -0,0 +1,22 @@
|
||||
{% extends "base.html" %}
|
||||
{% load crispy_forms_filters %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans 'Sign Out' %}{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<h1>{% trans "Sign Out" %}</h1>
|
||||
|
||||
<p>{% trans 'Are you sure you want to sign out?' %}</p>
|
||||
|
||||
<form method="post" action="{% url 'account_logout' %}">
|
||||
{% csrf_token %}
|
||||
{% if redirect_field_value %}
|
||||
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}"/>
|
||||
{% endif %}
|
||||
<button class="btn btn-warning" type="submit">{% trans 'Sign Out' %}</button>
|
||||
</form>
|
||||
|
||||
|
||||
{% endblock %}
|
11
cookbook/templates/account/password_reset.html
Normal file
11
cookbook/templates/account/password_reset.html
Normal file
@ -0,0 +1,11 @@
|
||||
{% extends "base.html" %}
|
||||
{% load crispy_forms_filters %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans 'Password Reset' %}{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<span>{% trans 'Password reset is not implemented for the time being!' %}</span>
|
||||
|
||||
{% endblock %}
|
11
cookbook/templates/account/password_reset_done.html
Normal file
11
cookbook/templates/account/password_reset_done.html
Normal file
@ -0,0 +1,11 @@
|
||||
{% extends "base.html" %}
|
||||
{% load crispy_forms_filters %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans 'Password Reset' %}{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<span>{% trans 'Password reset is not implemented for the time being!' %}</span>
|
||||
|
||||
{% endblock %}
|
20
cookbook/templates/no_groups_info.html
Normal file
20
cookbook/templates/no_groups_info.html
Normal file
@ -0,0 +1,20 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans "Offline" %}{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div style="text-align: center">
|
||||
|
||||
<h1 class="">{% trans 'No Permissions' %}</h1>
|
||||
<br/>
|
||||
|
||||
<span>{% trans 'You do not have any groups and therefor cannot use this application. Please contact your administrator.' %}</span> <br/>
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -1,52 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans 'Login' %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{% trans "Your username and password didn't match. Please try again." %}
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
||||
<form role="form" class="form-horizontal" method="post" action="{% url 'account_login' %}">
|
||||
{% csrf_token %}
|
||||
<div class="form-group">
|
||||
|
||||
<div class="form-group row">
|
||||
<label for='{{ form.username.label_tag }}' class="col-sm-2 col-form-label">{{ form.username.label }}</label>
|
||||
<div class="col-sm-10">
|
||||
<input class="form-control" id="{{ form.username.id_for_label }}"
|
||||
name="{{ form.username.html_name }}"/>
|
||||
</div>
|
||||
{% if form.username.errors %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ form.username.errors }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label for='{{ form.password.label_tag }}' class="col-sm-2 col-form-label">{{ form.password.label }}</label>
|
||||
<div class="col-sm-10">
|
||||
<input class="form-control" id="{{ form.password.id_for_label }}"
|
||||
name="{{ form.password.html_name }}" type="password"/>
|
||||
</div>
|
||||
{% if form.password.errors %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ form.password.errors }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<input type="submit" class="btn btn-primary" value="{% trans 'Login' %}"/>
|
||||
<input type="hidden" name="next" value="{{ next }}"/>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
{% endblock %}
|
@ -39,6 +39,7 @@ router.register(r'supermarket', api.SupermarketViewSet)
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
path('setup/', views.setup, name='view_setup'),
|
||||
path('no-group', views.no_groups, name='view_no_group'),
|
||||
path('signup/<slug:token>', views.signup, name='view_signup'),
|
||||
path('system/', views.system, name='view_system'),
|
||||
path('search/', views.search, name='view_search'),
|
||||
|
@ -23,7 +23,7 @@ from cookbook.filters import RecipeFilter
|
||||
from cookbook.forms import (CommentForm, Recipe, RecipeBookEntryForm, User,
|
||||
UserCreateForm, UserNameForm, UserPreference,
|
||||
UserPreferenceForm)
|
||||
from cookbook.helper.permission_helper import group_required, share_link_valid
|
||||
from cookbook.helper.permission_helper import group_required, share_link_valid, has_group_permission
|
||||
from cookbook.models import (Comment, CookLog, InviteLink, MealPlan,
|
||||
RecipeBook, RecipeBookEntry, ViewLog)
|
||||
from cookbook.tables import (CookLogTable, RecipeTable, RecipeTableSmall,
|
||||
@ -34,8 +34,7 @@ from recipes.version import BUILD_REF, VERSION_NUMBER
|
||||
|
||||
def index(request):
|
||||
if not request.user.is_authenticated:
|
||||
if (User.objects.count() < 1
|
||||
and 'django.contrib.auth.backends.RemoteUserBackend' not in settings.AUTHENTICATION_BACKENDS): # noqa: E501
|
||||
if User.objects.count() < 1 and 'django.contrib.auth.backends.RemoteUserBackend' not in settings.AUTHENTICATION_BACKENDS:
|
||||
return HttpResponseRedirect(reverse_lazy('view_setup'))
|
||||
return HttpResponseRedirect(reverse_lazy('view_search'))
|
||||
try:
|
||||
@ -45,15 +44,13 @@ def index(request):
|
||||
UserPreference.BOOKS: reverse_lazy('view_books'),
|
||||
}
|
||||
|
||||
return HttpResponseRedirect(
|
||||
page_map.get(request.user.userpreference.default_page)
|
||||
)
|
||||
return HttpResponseRedirect(page_map.get(request.user.userpreference.default_page))
|
||||
except UserPreference.DoesNotExist:
|
||||
return HttpResponseRedirect(reverse('account_login') + '?next=' + request.path)
|
||||
return HttpResponseRedirect(reverse('view_no_group') + '?next=' + request.path)
|
||||
|
||||
|
||||
def search(request):
|
||||
if request.user.is_authenticated:
|
||||
if has_group_permission(request.user, ('guest',)):
|
||||
f = RecipeFilter(
|
||||
request.GET,
|
||||
queryset=Recipe.objects.all().order_by('name')
|
||||
@ -88,19 +85,27 @@ def search(request):
|
||||
{'recipes': table, 'filter': f, 'last_viewed': last_viewed}
|
||||
)
|
||||
else:
|
||||
return HttpResponseRedirect(reverse('account_login') + '?next=' + request.path)
|
||||
return HttpResponseRedirect(reverse('view_no_group') + '?next=' + request.path)
|
||||
|
||||
|
||||
def no_groups(request):
|
||||
if not request.user.is_authenticated:
|
||||
return HttpResponseRedirect(reverse('account_login') + '?next=' + request.GET['next'])
|
||||
if request.user.is_authenticated and request.user.groups.count() > 0:
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
return render(request, 'no_groups_info.html')
|
||||
|
||||
|
||||
def recipe_view(request, pk, share=None):
|
||||
recipe = get_object_or_404(Recipe, pk=pk)
|
||||
|
||||
if not request.user.is_authenticated and not share_link_valid(recipe, share):
|
||||
if not has_group_permission(request.user, ('guest',)) and not share_link_valid(recipe, share):
|
||||
messages.add_message(
|
||||
request,
|
||||
messages.ERROR,
|
||||
_('You do not have the required permissions to view this page!')
|
||||
)
|
||||
return HttpResponseRedirect(reverse('account_login') + '?next=' + request.path)
|
||||
return HttpResponseRedirect(reverse('view_no_group') + '?next=' + request.path)
|
||||
|
||||
comments = Comment.objects.filter(recipe=recipe)
|
||||
|
||||
@ -197,22 +202,6 @@ def books(request):
|
||||
return render(request, 'books.html', {'book_list': book_list})
|
||||
|
||||
|
||||
def get_start_end_from_week(p_year, p_week):
|
||||
first_day_of_week = datetime.strptime(
|
||||
f'{p_year}-W{int(p_week) - 1}-1', "%Y-W%W-%w"
|
||||
).date()
|
||||
last_day_of_week = first_day_of_week + timedelta(days=6.9)
|
||||
return first_day_of_week, last_day_of_week
|
||||
|
||||
|
||||
def get_days_from_week(start, end):
|
||||
delta = end - start
|
||||
days = []
|
||||
for i in range(delta.days + 1):
|
||||
days.append(start + timedelta(days=i))
|
||||
return days
|
||||
|
||||
|
||||
@group_required('user')
|
||||
def meal_plan(request):
|
||||
return render(request, 'meal_plan.html', {})
|
||||
@ -466,7 +455,7 @@ def signup(request, token):
|
||||
form.fields['name'].initial = link.username
|
||||
form.fields['name'].disabled = True
|
||||
return render(
|
||||
request, 'registration/signup.html', {'form': form, 'link': link}
|
||||
request, 'account/signup.html', {'form': form, 'link': link}
|
||||
)
|
||||
|
||||
messages.add_message(
|
||||
|
@ -32,6 +32,20 @@ Please make sure, if you run your image this way, to consult
|
||||
the [.env.template](https://raw.githubusercontent.com/vabene1111/recipes/master/.env.template)
|
||||
file in the GitHub repository to verify if additional environment variables are required for your setup.
|
||||
|
||||
### Versions
|
||||
|
||||
There are different versions (tags) released on docker hub.
|
||||
|
||||
- **latest** Default image. The one you should use if you don't know that you need anything else.
|
||||
- **beta** Partially stable version that gets updated every now and then. Expect to have some problems.
|
||||
- **develop** If you want the most bleeding edge version with potentially many breaking changes feel free to use this version (I don't recommend it!).
|
||||
- **X.Y.Z** each released version has its own image. If you need to revert to an old version or want to make sure you stay on one specific use these tags.
|
||||
|
||||
!!! danger "No Downgrading"
|
||||
There is currently no way to migrate back to an older version as there is no mechanism to downgrade the database.
|
||||
You could probably do it but I cannot help you with that. Choose wisely if you want to use the unstable images.
|
||||
That said **beta** should usually be working if you like frequent updates and new stuff.
|
||||
|
||||
## Docker Compose
|
||||
|
||||
The main, and also recommended, installation option is to install this application using Docker Compose.
|
||||
|
Loading…
Reference in New Issue
Block a user