Setup basic auth

This commit is contained in:
Edgar P. Burkhart 2025-06-13 15:51:32 +02:00
parent 3294ef2a82
commit d7545ab43c
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
17 changed files with 315 additions and 4 deletions

0
base/__init__.py Normal file
View file

6
base/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class BaseConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "base"

View file

9
base/static/css/main.css Normal file
View file

@ -0,0 +1,9 @@
img.logo {
border-radius: var(--pico-border-radius);
}
header .container {
display: flex;
align-items: center;
justify-content: space-between;
}

25
base/static/logo.svg Normal file
View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="256" height="256" version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient id="Gradient" x1="0" x2="0" y1="0" y2="1">
<stop offset="0%" style="stop-color:#3584E4;stop-opacity:1" />
<stop offset="100%" style="stop-color:#A51D2D;stop-opacity:1" />
</linearGradient>
<filter id="alpha-to-white">
<feColorMatrix in="SourceGraphic" type="matrix"
values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
</filter>
<g id="child-svg"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" height="16px" width="16px"><path d="M18.7134 8.12811L18.4668 8.69379C18.2864 9.10792 17.7136 9.10792 17.5331 8.69379L17.2866 8.12811C16.8471 7.11947 16.0555 6.31641 15.0677 5.87708L14.308 5.53922C13.8973 5.35653 13.8973 4.75881 14.308 4.57612L15.0252 4.25714C16.0384 3.80651 16.8442 2.97373 17.2761 1.93083L17.5293 1.31953C17.7058 0.893489 18.2942 0.893489 18.4706 1.31953L18.7238 1.93083C19.1558 2.97373 19.9616 3.80651 20.9748 4.25714L21.6919 4.57612C22.1027 4.75881 22.1027 5.35653 21.6919 5.53922L20.9323 5.87708C19.9445 6.31641 19.1529 7.11947 18.7134 8.12811ZM7 3H12V6H9V17C9 19.2091 7.20914 21 5 21C2.79086 21 1 19.2091 1 17C1 14.7909 2.79086 13 5 13C5.72857 13 6.41165 13.1948 7 13.5351V3ZM18 13.5351V11H20V17C20 19.2091 18.2091 21 16 21C13.7909 21 12 19.2091 12 17C12 14.7909 13.7909 13 16 13C16.7286 13 17.4117 13.1948 18 13.5351Z" /></svg></g>
</defs>
<rect
width="256"
height="256"
fill="url(#Gradient)"
ry="0"
x="0"
y="0" />
<use xlink:href="#child-svg" filter="url(#alpha-to-white)"
transform="matrix(8,0,0,8,64,64)" />
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

36
base/templates/base.html Normal file
View file

@ -0,0 +1,36 @@
{% load static %}
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}Musik{% endblock %}</title>
<link rel="stylesheet" href="{% static "css/main.css" %}">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.purple.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/remixicon@4.6.0/fonts/remixicon.min.css">
</head>
<body>
<header>
<div class="container">
<a href="{% url 'index' %}">
<img class="logo" src="{% static "logo.svg" %}" height="64" width="64" alt="Musik">
</a>
<nav>
<ul>
{% if user.is_authenticated %}
<li>{{ user.username }}</li>
<li><form action="{% url 'logout' %}" method="post">{% csrf_token %}<input type="submit" value="Se déconnecter" class="logout"></form></li>
{% else %}
<li><a href="{% url 'login' %}" role="button">Se connecter <i class="ri-login-box-fill"></i></a></li>
{% endif %}
</ul>
</nav>
</div>
</header>
<main class="container">
{% block content %}
{% endblock content %}
</main>
</body>
</html>

View file

@ -0,0 +1,27 @@
{% if form.non_field_errors %}
<ul class="form-errors">
{% for error in form.non_field_errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
<form method="post" action="{% url "login" %}">
{% csrf_token %}
<fieldset>
{% for field in form %}
<label>
{{ field.label }}
{{ field }}
</label>
{% if field.errors %}
<ul class="form-errors">
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
</fieldset>
<input type="submit" {% if submit %}value="{{ submit }}"{% endif %}>
</form>

View file

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block content %}
<h1>Musik</h1>
{% endblock content %}

View file

@ -0,0 +1,7 @@
{% extends "base.html" %}
{% load form %}
{% block content %}
<h1>Connexion</h1>
{% form form submit="Se connecter" %}
{% endblock content %}

View file

11
base/templatetags/form.py Normal file
View file

@ -0,0 +1,11 @@
from django import template
register = template.Library()
@register.inclusion_tag("base/form.html")
def form(form, **kwargs):
return kwargs | {
"form": form,
"errors": form.errors,
}

8
base/urls.py Normal file
View file

@ -0,0 +1,8 @@
from django.urls import include, path
from . import views
urlpatterns = [
path("", views.HomePageView.as_view(), name="index"),
path("accounts/", include("django.contrib.auth.urls")),
]

5
base/views.py Normal file
View file

@ -0,0 +1,5 @@
from django.views.generic.base import TemplateView
class HomePageView(TemplateView):
template_name = "index.html"