Vaihe 1/1: users-moduuli, kirjautuminen ja käyttäjähallinta
- shared-moduuli: DomainError, EmailAddress, UnitOfWork, tapahtumat, TimestampedModel, daisyUI-lomakerenderöinti ja yhteiset pohjat - users-moduuli Clean Architecture -kerroksin: oma käyttäjämalli (AUTH_USER_MODEL), roolit ja oikeudet, harjoittelija-, vastuuhenkilö- ja viimeisen pääkäyttäjän säännöt - kirjautuminen sähköpostilla, yritysten rajoitus, "muista minut", istunnon katkaisu kun tunnus poistetaan käytöstä tai harjoittelu päättyy - kertakäyttöiset salasanalinkit (72 h / 60 min, uusi mitätöi vanhan), salasanasääntö ja create_admin-komento - käyttäjähallinta: lista (HTMX-haku), lomakkeet ja kopioitava linkki - Tailwind 4 + daisyUI 5 + HTMX + Alpine npm-buildilla, suomennokset - testit: domain, application (fakeilla), integraatio ja selaintestit (axe, vaalea/tumma, 1920/320 px); ruff, mypy ja import-linter - dokumentit päivitetty toteutuksen mukaisiksi Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
{% extends "layouts/auth.html" %}{% load i18n %}
|
||||
{% block title %}{% translate "Access denied" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="card-title text-2xl">{% translate "Access denied" %}</h1>
|
||||
<p>{% translate "You do not have permission to view this page." %}</p>
|
||||
<a class="btn btn-primary mt-4" href="/">{% translate "Back to home" %}</a>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,7 @@
|
||||
{% extends "layouts/auth.html" %}{% load i18n %}
|
||||
{% block title %}{% translate "Page not found" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="card-title text-2xl">{% translate "Page not found" %}</h1>
|
||||
<p>{% translate "The page you requested does not exist." %}</p>
|
||||
<a class="btn btn-primary mt-4" href="/">{% translate "Back to home" %}</a>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,75 @@
|
||||
{% load static i18n users_tags %}<!DOCTYPE html>
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<html lang="{{ LANGUAGE_CODE }}">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{% block title %}{% endblock %} – Toiminnanohjaus</title>
|
||||
<script>
|
||||
(function () {
|
||||
var t = localStorage.getItem("theme");
|
||||
if (t) document.documentElement.setAttribute("data-theme", t);
|
||||
})();
|
||||
</script>
|
||||
<link rel="stylesheet" href="{% static 'dist/app.css' %}">
|
||||
<script src="{% static 'dist/htmx.min.js' %}" defer></script>
|
||||
<script src="{% static 'dist/alpine.min.js' %}" defer></script>
|
||||
<script src="{% static 'src/app.js' %}" defer></script>
|
||||
</head>
|
||||
<body class="min-h-screen bg-base-200" hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
|
||||
<a href="#main" class="sr-only focus:not-sr-only focus:absolute focus:z-50 focus:m-2 btn btn-primary">{% translate "Skip to content" %}</a>
|
||||
{% block layout %}
|
||||
<div class="drawer lg:drawer-open" x-data="{ open: false }" @keydown.escape.window="open = false">
|
||||
<input id="nav-drawer" type="checkbox" class="drawer-toggle" x-model="open" tabindex="-1" aria-hidden="true">
|
||||
<div class="drawer-content flex flex-col">
|
||||
<header class="navbar bg-base-100 border-b border-base-300 gap-2">
|
||||
<button type="button" class="btn btn-ghost lg:hidden" aria-controls="main-nav" :aria-expanded="open.toString()"
|
||||
@click="open = !open; $nextTick(() => { if (open) $refs.nav.querySelector('a').focus() })">
|
||||
<span class="sr-only">{% translate "Open menu" %}</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"/></svg>
|
||||
</button>
|
||||
<a href="{% url 'home' %}" class="text-lg font-semibold px-2 truncate min-w-0">Toiminnanohjaus</a>
|
||||
<div class="flex-1"></div>
|
||||
<div class="hidden sm:block">{% include "components/theme_toggle.html" %}</div>
|
||||
<div class="dropdown dropdown-end hidden sm:block">
|
||||
<button type="button" class="btn btn-ghost" aria-haspopup="true">{{ request.user.name }}</button>
|
||||
<ul class="dropdown-content menu bg-base-100 rounded-box shadow z-10 w-56 p-2">
|
||||
<li>
|
||||
<form method="post" action="{% url 'users:logout' %}">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="w-full text-left">{% translate "Log out" %}</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</header>
|
||||
<main id="main" tabindex="-1" class="p-4 lg:p-6 max-w-7xl w-full">
|
||||
{% include "components/messages.html" %}
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
</div>
|
||||
<div class="drawer-side z-20">
|
||||
<label for="nav-drawer" class="drawer-overlay" aria-hidden="true"></label>
|
||||
<nav id="main-nav" x-ref="nav" aria-label="{% translate 'Main menu' %}" class="bg-base-100 min-h-full w-64 border-r border-base-300">
|
||||
<ul class="menu w-full p-4 gap-1">
|
||||
<li><a href="{% url 'home' %}" {% if request.resolver_match.url_name == 'home' %}aria-current="page" class="menu-active"{% endif %}>{% translate "Home" %}</a></li>
|
||||
{% if request.user|can:"users.manage" %}
|
||||
<li class="menu-title">{% translate "Administration" %}</li>
|
||||
<li><a href="{% url 'users:list' %}" {% if request.resolver_match.app_name == 'users' %}aria-current="page" class="menu-active"{% endif %}>{% translate "Users" %}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<div class="sm:hidden border-t border-base-300 p-4 space-y-2">
|
||||
<p class="font-semibold">{{ request.user.name }}</p>
|
||||
{% include "components/theme_toggle.html" %}
|
||||
<form method="post" action="{% url 'users:logout' %}">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-ghost btn-sm">{% translate "Log out" %}</button>
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
<div id="live-region" class="sr-only" role="status" aria-live="polite" aria-atomic="true"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,17 @@
|
||||
{% load i18n %}
|
||||
{# Usage: include with id, title, body, action_url, confirm_label (and optional hx_target). #}
|
||||
<dialog id="{{ id }}" class="modal" aria-labelledby="{{ id }}-title">
|
||||
<div class="modal-box">
|
||||
<h2 id="{{ id }}-title" class="text-lg font-bold">{{ title }}</h2>
|
||||
<p class="py-4">{{ body }}</p>
|
||||
<div class="modal-action">
|
||||
<form method="dialog"><button class="btn">{% translate "Cancel" %}</button></form>
|
||||
<form method="post" action="{{ action_url }}"
|
||||
{% if hx_target %}hx-post="{{ action_url }}" hx-target="{{ hx_target }}" hx-swap="innerHTML"
|
||||
hx-on::after-request="this.closest('dialog').close()"{% endif %}>
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-primary">{{ confirm_label }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
@@ -0,0 +1,23 @@
|
||||
{% load i18n %}{% with widget_type=field.widget_type %}
|
||||
<div class="fieldset {% if field.field.widget.input_type == 'hidden' %}hidden{% endif %}">
|
||||
{% if widget_type == "checkbox" %}
|
||||
<label class="label cursor-pointer justify-start gap-3 text-base-content" for="{{ field.auto_id }}">
|
||||
{{ field }}
|
||||
<span>{{ field.label }}</span>
|
||||
</label>
|
||||
{% else %}
|
||||
<label class="fieldset-legend text-sm" for="{{ field.auto_id }}">
|
||||
{{ field.label }}{% if field.field.required %} <span aria-hidden="true">*</span><span class="sr-only">{% translate "(required)" %}</span>{% endif %}
|
||||
</label>
|
||||
{{ field }}
|
||||
{% endif %}
|
||||
{% if field.help_text %}
|
||||
<p class="label text-sm whitespace-normal" id="{{ field.auto_id }}_helptext">{{ field.help_text }}</p>
|
||||
{% endif %}
|
||||
{% if field.errors %}
|
||||
<p class="text-error text-sm" id="{{ field.auto_id }}_error">
|
||||
{% for error in field.errors %}{{ error }}{% if not forloop.last %} {% endif %}{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endwith %}
|
||||
@@ -0,0 +1,3 @@
|
||||
{% include "components/non_field_errors.html" %}
|
||||
{% for field, errors in fields %}{{ field.as_field_group }}{% endfor %}
|
||||
{% for field in hidden_fields %}{{ field }}{% endfor %}
|
||||
@@ -0,0 +1,9 @@
|
||||
{% if messages %}
|
||||
<div class="space-y-2 mb-4" id="messages" tabindex="-1" data-autofocus>
|
||||
{% for message in messages %}
|
||||
<div role="status" class="alert {% if message.level_tag == 'error' %}alert-error{% elif message.level_tag == 'warning' %}alert-warning{% elif message.level_tag == 'success' %}alert-success{% else %}alert-info{% endif %} alert-soft">
|
||||
<span>{{ message }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -0,0 +1,5 @@
|
||||
{% if form.non_field_errors %}
|
||||
<div role="alert" class="alert alert-error alert-soft">
|
||||
<span>{% for error in form.non_field_errors %}{{ error }}{% if not forloop.last %} {% endif %}{% endfor %}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -0,0 +1,7 @@
|
||||
{% load i18n %}
|
||||
<div x-data="{ dark: document.documentElement.getAttribute('data-theme') === 'dark' || (!document.documentElement.getAttribute('data-theme') && window.matchMedia('(prefers-color-scheme: dark)').matches) }">
|
||||
<button type="button" class="btn btn-ghost btn-sm" :aria-pressed="dark.toString()"
|
||||
@click="dark = !dark; setTheme(dark ? 'dark' : 'light')">
|
||||
{% translate "Dark theme" %}
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,6 @@
|
||||
{% extends "base.html" %}{% load i18n %}
|
||||
{% block title %}{% translate "Home" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="text-2xl font-bold mb-4">{% blocktranslate with name=request.user.name %}Welcome, {{ name }}{% endblocktranslate %}</h1>
|
||||
<p>{% translate "The dashboard will be built in a later step." %}</p>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,13 @@
|
||||
{% extends "base.html" %}{% load i18n %}
|
||||
{% block layout %}
|
||||
<div class="min-h-screen flex flex-col items-center justify-center p-4">
|
||||
<div class="w-full max-w-md flex justify-end mb-2">{% include "components/theme_toggle.html" %}</div>
|
||||
<main id="main" tabindex="-1" class="card bg-base-100 shadow w-full max-w-md">
|
||||
<div class="card-body">
|
||||
<p class="text-sm font-semibold text-base-content/70">Toiminnanohjaus</p>
|
||||
{% include "components/messages.html" %}
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user