Added authentication
This commit is contained in:
parent
61edb7e538
commit
13cc1c3f57
|
@ -2,11 +2,13 @@ from django.views import generic
|
|||
from .models import Container, ContainerType
|
||||
import logging, json, re
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ContainerListView(generic.ListView):
|
||||
class ContainerListView(LoginRequiredMixin, generic.ListView):
|
||||
model = Container
|
||||
template_name = 'container/container_list.html'
|
||||
context_object_name = 'container_list'
|
||||
|
@ -19,7 +21,7 @@ class ContainerListView(generic.ListView):
|
|||
'''
|
||||
|
||||
|
||||
class ContainerCreateView(generic.CreateView):
|
||||
class ContainerCreateView(LoginRequiredMixin, generic.CreateView):
|
||||
model = Container
|
||||
# template_name = 'container/detail.html'
|
||||
fields = ['named_id', 'description', 'color', 'container_type']
|
||||
|
@ -30,7 +32,7 @@ class ContainerCreateView(generic.CreateView):
|
|||
return super().form_valid(form)
|
||||
|
||||
|
||||
class ContainerImportView(generic.TemplateView):
|
||||
class ContainerImportView(LoginRequiredMixin, generic.TemplateView):
|
||||
template_name = 'container_import.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
@ -47,7 +49,7 @@ class ContainerImportView(generic.TemplateView):
|
|||
return super().render_to_response(self)
|
||||
|
||||
|
||||
class ContainerUpdateView(generic.UpdateView):
|
||||
class ContainerUpdateView(LoginRequiredMixin, generic.UpdateView):
|
||||
model = Container
|
||||
# template_name = 'container/detail.html'
|
||||
fields = ['named_id', 'description', 'color', 'container_type']
|
||||
|
@ -57,15 +59,15 @@ class ContainerUpdateView(generic.UpdateView):
|
|||
return super().form_valid(form)
|
||||
|
||||
|
||||
class ContainerDetailView(generic.DetailView):
|
||||
class ContainerDetailView(LoginRequiredMixin, generic.DetailView):
|
||||
model = Container
|
||||
|
||||
|
||||
class ContainerDeleteView(generic.DetailView):
|
||||
class ContainerDeleteView(LoginRequiredMixin, generic.DetailView):
|
||||
model = Container
|
||||
|
||||
|
||||
class ContainerPrintLabelView(generic.DetailView):
|
||||
class ContainerPrintLabelView(LoginRequiredMixin, generic.DetailView):
|
||||
model = Container
|
||||
template_name = 'container/container_print_label.html'
|
||||
|
||||
|
@ -160,7 +162,7 @@ class ContainerPrintLabelView(generic.DetailView):
|
|||
return context
|
||||
|
||||
|
||||
class ContainerTypeListView(generic.ListView):
|
||||
class ContainerTypeListView(LoginRequiredMixin, generic.ListView):
|
||||
template_name = 'container/container_type_list.html'
|
||||
context_object_name = 'container_type_list'
|
||||
paginate_by = 20
|
||||
|
@ -173,13 +175,13 @@ class ContainerTypeListView(generic.ListView):
|
|||
'''
|
||||
|
||||
|
||||
class ContainerTypeDetailView(generic.DetailView):
|
||||
class ContainerTypeDetailView(LoginRequiredMixin, generic.DetailView):
|
||||
model = ContainerType
|
||||
context_object_name = 'container_type'
|
||||
template_name = 'container/container_type_detail.html'
|
||||
|
||||
|
||||
class ContainerTypeCreateView(generic.CreateView):
|
||||
class ContainerTypeCreateView(LoginRequiredMixin, generic.CreateView):
|
||||
model = ContainerType
|
||||
template_name = 'container/container_type_form.html'
|
||||
fields = ['named_id', 'description', 'width', 'length', 'height', 'inner_width', 'inner_length', 'inner_height',
|
||||
|
@ -191,7 +193,7 @@ class ContainerTypeCreateView(generic.CreateView):
|
|||
return super().form_valid(form)
|
||||
|
||||
|
||||
class ContainerTypeUpdateView(generic.UpdateView):
|
||||
class ContainerTypeUpdateView(LoginRequiredMixin, generic.UpdateView):
|
||||
model = ContainerType
|
||||
# template_name = 'container/detail.html'
|
||||
template_name = 'container/container_type_form.html'
|
||||
|
@ -203,11 +205,11 @@ class ContainerTypeUpdateView(generic.UpdateView):
|
|||
return super().form_valid(form)
|
||||
|
||||
|
||||
class ContainerTypeDeleteView(generic.DetailView):
|
||||
class ContainerTypeDeleteView(LoginRequiredMixin, generic.DetailView):
|
||||
model = ContainerType
|
||||
|
||||
|
||||
class ContainerTypeImportView(generic.TemplateView):
|
||||
class ContainerTypeImportView(LoginRequiredMixin, generic.TemplateView):
|
||||
template_name = 'container/container_type_import.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
|
|
@ -132,3 +132,5 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|||
|
||||
MEDIA_URL = '/media/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
|
||||
LOGIN_URL = '/accounts/login/'
|
||||
|
|
|
@ -61,12 +61,11 @@
|
|||
{% if request.user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
{# URL provided by django-allauth/account/urls.py #}
|
||||
{# <a class="nav-link" href="{% url 'users:detail' request.user.username %}">{% translate "My Profile" %}</a> #}
|
||||
nyi my profile
|
||||
{#<a class="nav-link" href="{% url 'users_detail' request.user.username %}">{% translate "My Profile" %}</a>#}
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
{# URL provided by django-allauth/account/urls.py #}
|
||||
{# <a class="nav-link" href="{% url 'account_logout' %}">{% translate "Sign Out" %}</a> #} Logout
|
||||
<a class="nav-link" href="{% url 'logout' %}">{% translate "Logout" %}</a>
|
||||
</li>
|
||||
{% else %}
|
||||
{% if ACCOUNT_ALLOW_REGISTRATION %}
|
||||
|
@ -77,7 +76,7 @@
|
|||
{% endif %}
|
||||
<li class="nav-item">
|
||||
{# URL provided by django-allauth/account/urls.py #}
|
||||
<a id="log-in-link" class="nav-link" href="{% url 'account_login' %}">{% translate "Sign In" %}</a>
|
||||
<a id="log-in-link" class="nav-link" href="{% url 'login' %}">{% translate "Login" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block breadcrumbs %}<div class="breadcrumbs"><a href="{% url 'index' %}">{% translate 'Home' %}</a></div>{% endblock %}
|
||||
|
||||
{% block nav-sidebar %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="container">
|
||||
{% translate "Thanks for spending some quality time with the web site today." %}
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<a class="btn btn-primary" href="{% url 'home' %}">{% translate 'Log in again' %}</a>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,76 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n static %}
|
||||
|
||||
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/login.css" %}">
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
|
||||
{% block bodyclass %}{{ block.super }} login{% endblock %}
|
||||
|
||||
{% block usertools %}{% endblock %}
|
||||
|
||||
{% block nav-global %}{% endblock %}
|
||||
|
||||
{% block nav-sidebar %}{% endblock %}
|
||||
|
||||
{% block content_title %}{% endblock %}
|
||||
|
||||
{% block breadcrumbs %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if form.errors and not form.non_field_errors %}
|
||||
<p class="errornote">
|
||||
{% if form.errors.items|length == 1 %}{% translate "Please correct the error below." %}{% else %}{% translate "Please correct the errors below." %}{% endif %}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if form.non_field_errors %}
|
||||
{% for error in form.non_field_errors %}
|
||||
<p class="errornote">
|
||||
{{ error }}
|
||||
</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<div id="content-main">
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
<p class="errornote">
|
||||
{% blocktranslate trimmed %}
|
||||
You are authenticated as {{ username }}, but are not authorized to
|
||||
access this page. Would you like to login to a different account?
|
||||
{% endblocktranslate %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<div class="container">
|
||||
<form action="{{ app_path }}" method="post" id="login-form">{% csrf_token %}
|
||||
<div class="row">
|
||||
<div class="col-2">
|
||||
{{ form.username.errors }}
|
||||
{{ form.username.label_tag }} {{ form.username }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-2">
|
||||
{{ form.password.errors }}
|
||||
{{ form.password.label_tag }} {{ form.password }}
|
||||
<input type="hidden" name="next" value="{{ next }}">
|
||||
</div>
|
||||
</div>
|
||||
{% url 'admin_password_reset' as password_reset_url %}
|
||||
{% if password_reset_url %}
|
||||
<div class="password-reset-link">
|
||||
<a class="btn btn-secondary" href="{{ password_reset_url }}">{% translate 'Forgotten your password or username?' %}</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
<div class="col-2">
|
||||
<input class="btn btn-primary" type="submit" value="{% translate 'Log in' %}">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -29,5 +29,5 @@ urlpatterns = [
|
|||
path('container/', include('container.urls')),
|
||||
path('asset/', include('asset.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
path('accounts/login/', auth_views.LoginView.as_view(), name='account_login'),
|
||||
path('accounts/', include('django.contrib.auth.urls')),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue