Add login form and require permissions

This commit is contained in:
George Lacey 2021-05-07 21:12:37 +01:00
parent 9f71901a49
commit 3babf80a3b
4 changed files with 26 additions and 3 deletions

View File

@ -4,6 +4,7 @@ from django.http import HttpResponseRedirect
from .models import Repo, Label, Archive, Cache, Error
from django.urls import reverse
from .forms import RepoForm, ArchiveForm, ErrorForm
from django.contrib.auth.decorators import permission_required
def index(request):
@ -17,6 +18,7 @@ def index(request):
return render(request, 'borg/index.html', context)
@permission_required("borg.add_repo")
def get_repo(request):
if request.method == 'POST':
form = RepoForm(request.POST)
@ -44,6 +46,7 @@ def get_repo(request):
return render(request, 'borg/repo.html', {'form': form})
@permission_required("borg.add_archive")
def get_archive(request):
if request.method == 'POST':
form = ArchiveForm(request.POST)
@ -71,6 +74,7 @@ def get_archive(request):
return render(request, 'borg/archive.html', {'form': form})
@permission_required("borg.add_error")
def get_error(request):
if request.method == 'POST':
form = ErrorForm(request.POST)

View File

@ -54,10 +54,12 @@ MIDDLEWARE = [
ROOT_URLCONF = 'borgweb.urls'
LOGIN_REDIRECT_URL = '/'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [str(BASE_DIR.joinpath('templates'))],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [

View File

@ -15,9 +15,9 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import include, path
from django.http import HttpResponseRedirect
urlpatterns = [
path('', include('borg.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('admin/', admin.site.urls),
path('', include('borg.urls')),
]

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
{% block content %}
<h2>Log In</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Log In</button>
</form>
{% endblock %}
</body>
</html>