Added basic user authentication.

This commit is contained in:
2023-08-23 17:45:39 -04:00
parent 511acab59c
commit bac5437e7e
8 changed files with 95 additions and 13 deletions

View File

@@ -44,6 +44,10 @@ body {
width: 100%;
}
.pd {
padding: 10%;
}
/****************************************************************************
* Content. *
****************************************************************************/
@@ -83,7 +87,7 @@ body {
margin-left: 2em;
}
.search-btn {
.clear-btn {
border: none;
background-color: #00000000;
}
@@ -92,6 +96,10 @@ body {
height: 2.5em;
}
.float-right {
float: right;
}
/****************************************************************************
* Grid. *
****************************************************************************/

BIN
viewer/static/imgs/boot.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -43,11 +43,21 @@
<!-- Page links. -->
{% if num_pages > 1 %}
<td>
<div class="mauto">
<div class="mauto mr-2">
{% for page in pages %}<a href="./?page={{page}}{%if search %}&{{search}}{% endif %}">{{page}}</a>{% if not forloop.last %}<span> </span>{% endif %}{% endfor %}
</div>
</td>
{% endif %}
<!-- Logout button. -->
<td>
<form method="post" action="{% url 'logout' %}">
{% csrf_token %}
<button type="submit" class="clear-btn">
<img src="{% static 'imgs/boot.png' %}" class="small-nav-icon">
</button>
</form>
</td>
</tr>
</table>
@@ -70,7 +80,7 @@
<!-- Search submit. -->
<td>
<button type="submit" class="search-btn">
<button type="submit" class="clear-btn">
<img src="{% static 'imgs/find.png' %}" class="small-nav-icon">
</button>
</td>

View File

@@ -0,0 +1,42 @@
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, height=device-height" />
<title>
NibasaViewer login
</title>
<link href="{% static 'css/styles.css' %}" rel="stylesheet">
</head>
<body class="background">
<div class="fc mauto pd">
<form method="post" action="{% url 'login' %}" class="fc">
{% csrf_token %}
<table>
<tr>
<td>
{{ form.username.label_tag }}
</td>
<td>
{{ form.username }}
</td>
</tr>
<tr>
<td>
{{ form.password.label_tag }}
</td>
<td>
{{ form.password }}
</td>
</tr>
</table>
<input type="submit" value="login" class="float-right">
<input type="hidden" name="next" value="{{ next }}">
</form>
</div>
</body>
</html>

View File

@@ -6,11 +6,15 @@ from math import ceil
import filetype
# Django imports.
from django.http import HttpResponseNotFound
from django.conf import settings
from django.utils.http import urlencode
from django.shortcuts import (render,
redirect)
from django.http import HttpResponseNotFound
from django.conf import settings
from django.utils.http import urlencode
from django.contrib.auth.decorators import login_required
from django.contrib.auth import (authenticate,
login,
logout)
from django.shortcuts import (render,
redirect)
# Project imports.
from .utils import make_thumbnail
@@ -24,12 +28,9 @@ ROWS_PER_PAGE = 4
IMAGES_PER_PAGE = CELLS_PER_ROW * ROWS_PER_PAGE
###########################################################################################
# View functions. #
# Helper functions. #
###########################################################################################
def index(request):
return redirect('gallery_view_root')
def do_recursive_search(start_path, query):
"""
Gets all images and sub-directories inside the start_path whose name matches the given query,
@@ -56,6 +57,11 @@ def do_recursive_search(start_path, query):
# View functions. #
###########################################################################################
@login_required
def index(request):
return redirect('gallery_view_root')
@login_required
def gallery_view(request, path = None):
"""
Shows a list of subdirectories and image files inside the given path.