Add login form and require permissions
This commit is contained in:
parent
9f71901a49
commit
3babf80a3b
|
@ -4,6 +4,7 @@ from django.http import HttpResponseRedirect
|
||||||
from .models import Repo, Label, Archive, Cache, Error
|
from .models import Repo, Label, Archive, Cache, Error
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from .forms import RepoForm, ArchiveForm, ErrorForm
|
from .forms import RepoForm, ArchiveForm, ErrorForm
|
||||||
|
from django.contrib.auth.decorators import permission_required
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
|
@ -17,6 +18,7 @@ def index(request):
|
||||||
return render(request, 'borg/index.html', context)
|
return render(request, 'borg/index.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
@permission_required("borg.add_repo")
|
||||||
def get_repo(request):
|
def get_repo(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = RepoForm(request.POST)
|
form = RepoForm(request.POST)
|
||||||
|
@ -44,6 +46,7 @@ def get_repo(request):
|
||||||
return render(request, 'borg/repo.html', {'form': form})
|
return render(request, 'borg/repo.html', {'form': form})
|
||||||
|
|
||||||
|
|
||||||
|
@permission_required("borg.add_archive")
|
||||||
def get_archive(request):
|
def get_archive(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = ArchiveForm(request.POST)
|
form = ArchiveForm(request.POST)
|
||||||
|
@ -71,6 +74,7 @@ def get_archive(request):
|
||||||
return render(request, 'borg/archive.html', {'form': form})
|
return render(request, 'borg/archive.html', {'form': form})
|
||||||
|
|
||||||
|
|
||||||
|
@permission_required("borg.add_error")
|
||||||
def get_error(request):
|
def get_error(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = ErrorForm(request.POST)
|
form = ErrorForm(request.POST)
|
||||||
|
|
|
@ -54,10 +54,12 @@ MIDDLEWARE = [
|
||||||
|
|
||||||
ROOT_URLCONF = 'borgweb.urls'
|
ROOT_URLCONF = 'borgweb.urls'
|
||||||
|
|
||||||
|
LOGIN_REDIRECT_URL = '/'
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [],
|
'DIRS': [str(BASE_DIR.joinpath('templates'))],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
|
|
|
@ -15,9 +15,9 @@ Including another URLconf
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from django.http import HttpResponseRedirect
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include('borg.urls')),
|
path('accounts/', include('django.contrib.auth.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('', include('borg.urls')),
|
||||||
]
|
]
|
||||||
|
|
17
borgweb/templates/registration/login.html
Normal file
17
borgweb/templates/registration/login.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user