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,10 @@
|
||||
{% autoescape off %}{% blocktranslate %}Hello {{ name }},{% endblocktranslate %}
|
||||
|
||||
{% if purpose == "reset" %}{% translate "You asked for a link for setting a new password." %}{% else %}{% translate "An account has been created or a new password link has been requested for you." %}{% endif %}
|
||||
{% translate "Set your password with this link:" %}
|
||||
|
||||
{{ url }}
|
||||
|
||||
{% blocktranslate with expires=expires_at|date:"j.n.Y H:i" %}The link can be used once and it is valid until {{ expires }}.{% endblocktranslate %}
|
||||
{% translate "If you did not expect this message, you can ignore it." %}
|
||||
{% endautoescape %}
|
||||
@@ -0,0 +1 @@
|
||||
{% if purpose == "reset" %}{% translate "Set a new password" %}{% else %}{% translate "Set your password" %}{% endif %} – Toiminnanohjaus
|
||||
@@ -0,0 +1,12 @@
|
||||
{% extends "layouts/auth.html" %}
|
||||
{% block title %}{% translate "Forgot your password?" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="card-title text-2xl">{% translate "Forgot your password?" %}</h1>
|
||||
<p>{% translate "Enter your email address. We will send you a link for setting a new password." %}</p>
|
||||
<form method="post" novalidate class="space-y-2">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<button type="submit" class="btn btn-primary w-full mt-2">{% translate "Send link" %}</button>
|
||||
</form>
|
||||
<a class="link mt-2" href="{% url 'users:login' %}">{% translate "Back to login" %}</a>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,48 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{% if user_id %}{% translate "Edit user" %}{% else %}{% translate "New user" %}{% endif %}{% endblock %}
|
||||
{% block content %}
|
||||
<nav class="breadcrumbs text-sm" aria-label="{% translate 'Breadcrumbs' %}">
|
||||
<ul><li><a href="{% url 'users:list' %}">{% translate "Users" %}</a></li>
|
||||
<li aria-current="page">{% if user_id %}{{ user_name }}{% else %}{% translate "New user" %}{% endif %}</li></ul>
|
||||
</nav>
|
||||
<h1 class="text-2xl font-bold mb-4">{% if user_id %}{% translate "Edit user" %}{% else %}{% translate "New user" %}{% endif %}</h1>
|
||||
|
||||
<div class="grid gap-4 lg:grid-cols-3">
|
||||
<form method="post" novalidate class="card bg-base-100 shadow-sm lg:col-span-2"
|
||||
x-data="{ role: '{{ form.role.value|default:'employee'|escapejs }}' }">
|
||||
{% csrf_token %}
|
||||
<div class="card-body">
|
||||
{% include "components/non_field_errors.html" %}
|
||||
{{ form.name.as_field_group }}
|
||||
{{ form.email.as_field_group }}
|
||||
{{ form.role.as_field_group }}
|
||||
<div x-show="role === 'intern'" x-cloak class="border-l-4 border-base-300 pl-4">
|
||||
<p class="text-sm">{% translate "An intern must have a last day and a supervisor." %}</p>
|
||||
{{ form.employment_ends_on.as_field_group }}
|
||||
{{ form.supervisor_id.as_field_group }}
|
||||
</div>
|
||||
{% if form.is_active %}{{ form.is_active.as_field_group }}{% endif %}
|
||||
<div class="card-actions justify-end mt-4">
|
||||
<a href="{% url 'users:list' %}" class="btn">{% translate "Cancel" %}</a>
|
||||
<button type="submit" class="btn btn-primary">{% translate "Save" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% if user_id %}
|
||||
<section class="card bg-base-100 shadow-sm" aria-labelledby="password-link-title">
|
||||
<div class="card-body">
|
||||
<h2 id="password-link-title" class="card-title">{% translate "Password link" %}</h2>
|
||||
<p class="text-sm">{% translate "Creates a new link for setting the password. The link is emailed to the user and shown here for copying. Earlier links stop working." %}</p>
|
||||
<button type="button" class="btn" onclick="document.getElementById('confirm-password-link').showModal()">{% translate "Create password link" %}</button>
|
||||
<div id="password-link-result"></div>
|
||||
</div>
|
||||
</section>
|
||||
{% url 'users:password_link' user_id as link_url %}
|
||||
{% translate "Create a new password link?" as dialog_title %}
|
||||
{% translate "Earlier links of this user stop working." as dialog_body %}
|
||||
{% translate "Create link" as dialog_confirm %}
|
||||
{% include "components/confirm_dialog.html" with id="confirm-password-link" title=dialog_title body=dialog_body action_url=link_url confirm_label=dialog_confirm hx_target="#password-link-result" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,24 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{% translate "Users" %}{% endblock %}
|
||||
{% block content %}
|
||||
<div class="flex flex-wrap items-center justify-between gap-2 mb-4">
|
||||
<h1 class="text-2xl font-bold">{% translate "Users" %}</h1>
|
||||
<a href="{% url 'users:create' %}" class="btn btn-primary">{% translate "New user" %}</a>
|
||||
</div>
|
||||
|
||||
<form method="get" role="search" aria-label="{% translate 'Filter users' %}"
|
||||
class="card bg-base-100 shadow-sm mb-4"
|
||||
hx-get="{% url 'users:list' %}" hx-target="#user-table" hx-push-url="true"
|
||||
hx-trigger="input changed delay:300ms from:input[name='q'], change from:select, submit">
|
||||
<div class="card-body grid gap-2 sm:grid-cols-3 py-4">
|
||||
{{ filters.q.as_field_group }}
|
||||
{{ filters.role.as_field_group }}
|
||||
{{ filters.active.as_field_group }}
|
||||
<noscript><button type="submit" class="btn">{% translate "Filter" %}</button></noscript>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div id="user-table">
|
||||
{% include "users/partials/user_table.html" %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,17 @@
|
||||
{% extends "layouts/auth.html" %}
|
||||
{% block title %}{% translate "Log in" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="card-title text-2xl">{% translate "Log in" %}</h1>
|
||||
{% if access_ended %}
|
||||
<div role="alert" class="alert alert-warning alert-soft">
|
||||
<span>{% translate "Your access has ended: the account has been deactivated or the internship has ended. Contact the admin if you think this is a mistake." %}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<form method="post" novalidate class="space-y-2">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<input type="hidden" name="next" value="{{ next }}">
|
||||
<button type="submit" class="btn btn-primary w-full mt-2">{% translate "Log in" %}</button>
|
||||
</form>
|
||||
<a class="link mt-2" href="{% url 'users:forgot_password' %}">{% translate "Forgot your password?" %}</a>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,20 @@
|
||||
<div class="space-y-2 mt-2" x-data="{ copied: false }" tabindex="-1" data-autofocus id="password-link-box">
|
||||
<p role="status">
|
||||
{% if link.emailed %}
|
||||
{% blocktranslate with email=user_summary.email %}The link has been emailed to {{ email }}.{% endblocktranslate %}
|
||||
{% else %}
|
||||
<span class="text-error font-semibold">{% translate "Sending the email failed." %}</span>
|
||||
{% translate "Deliver the link to the user in another way." %}
|
||||
{% endif %}
|
||||
{% blocktranslate with expires=link.expires_at|date:"j.n.Y H:i" %}Valid until {{ expires }}.{% endblocktranslate %}
|
||||
</p>
|
||||
<label class="fieldset-legend text-sm" for="password-link-url">{% translate "Link" %}</label>
|
||||
<div class="join w-full">
|
||||
<input id="password-link-url" class="input join-item w-full" readonly value="{{ link.url }}" x-ref="url">
|
||||
<button type="button" class="btn btn-primary join-item"
|
||||
@click="navigator.clipboard.writeText($refs.url.value).then(() => { copied = true; notify('{% translate "Link copied" %}') })">
|
||||
{% translate "Copy" %}
|
||||
</button>
|
||||
</div>
|
||||
<p x-show="copied" class="text-success text-sm">{% translate "Link copied" %}</p>
|
||||
</div>
|
||||
@@ -0,0 +1,47 @@
|
||||
{% load users_tags %}
|
||||
<p class="sr-only" role="status">{% blocktranslate count counter=page.paginator.count %}{{ counter }} user found{% plural %}{{ counter }} users found{% endblocktranslate %}</p>
|
||||
<div class="overflow-x-auto card bg-base-100 shadow-sm">
|
||||
<table class="table">
|
||||
<caption class="sr-only">{% translate "Users" %}</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{% translate "Name" %}</th>
|
||||
<th scope="col">{% translate "Email" %}</th>
|
||||
<th scope="col">{% translate "Role" %}</th>
|
||||
<th scope="col">{% translate "Status" %}</th>
|
||||
<th scope="col">{% translate "Last day" %}</th>
|
||||
<th scope="col">{% translate "Supervisor" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for u in page.object_list %}
|
||||
<tr>
|
||||
<td><a class="link" href="{% url 'users:edit' u.id %}">{{ u.name }}</a></td>
|
||||
<td class="break-all">{{ u.email }}</td>
|
||||
<td>{{ u.role|role_label }}</td>
|
||||
<td>
|
||||
{% if u.is_active %}<span class="badge badge-success badge-soft">{% translate "Active" %}</span>
|
||||
{% else %}<span class="badge badge-ghost">{% translate "Inactive" %}</span>{% endif %}
|
||||
</td>
|
||||
<td>{{ u.employment_ends_on|date:"j.n.Y"|default:"–" }}</td>
|
||||
<td>{{ u.supervisor_name|default:"–" }}</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr><td colspan="6">{% translate "No users match the filters." %}</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% if page.paginator.num_pages > 1 %}
|
||||
<nav aria-label="{% translate 'Pages' %}" class="join mt-4">
|
||||
{% if page.has_previous %}
|
||||
<a class="join-item btn" href="?{{ query }}{% if query %}&{% endif %}page={{ page.previous_page_number }}"
|
||||
hx-get="?{{ query }}{% if query %}&{% endif %}page={{ page.previous_page_number }}" hx-target="#user-table" hx-push-url="true">{% translate "Previous" %}</a>
|
||||
{% endif %}
|
||||
<span class="join-item btn btn-disabled" aria-current="page">{% blocktranslate with n=page.number total=page.paginator.num_pages %}Page {{ n }} / {{ total }}{% endblocktranslate %}</span>
|
||||
{% if page.has_next %}
|
||||
<a class="join-item btn" href="?{{ query }}{% if query %}&{% endif %}page={{ page.next_page_number }}"
|
||||
hx-get="?{{ query }}{% if query %}&{% endif %}page={{ page.next_page_number }}" hx-target="#user-table" hx-push-url="true">{% translate "Next" %}</a>
|
||||
{% endif %}
|
||||
</nav>
|
||||
{% endif %}
|
||||
@@ -0,0 +1,14 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{% translate "Password link" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="text-2xl font-bold mb-4">{% blocktranslate with name=user_summary.name %}Password link for {{ name }}{% endblocktranslate %}</h1>
|
||||
<div class="card bg-base-100 shadow-sm max-w-2xl">
|
||||
<div class="card-body">
|
||||
{% include "users/partials/password_link.html" %}
|
||||
<div class="card-actions mt-4">
|
||||
<a href="{% url 'users:edit' user_summary.id %}" class="btn">{% translate "Edit user" %}</a>
|
||||
<a href="{% url 'users:list' %}" class="btn btn-primary">{% translate "Back to users" %}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,10 @@
|
||||
{% extends "layouts/auth.html" %}
|
||||
{% block title %}{% translate "Set password" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="card-title text-2xl">{% translate "Set password" %}</h1>
|
||||
<form method="post" novalidate class="space-y-2">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<button type="submit" class="btn btn-primary w-full mt-2">{% translate "Set password" %}</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,7 @@
|
||||
{% extends "layouts/auth.html" %}
|
||||
{% block title %}{% translate "The link is not valid" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="card-title text-2xl">{% translate "The link is not valid" %}</h1>
|
||||
<p>{% translate "The link has expired, it has already been used, or a newer link has been created. Request a new link or ask the admin to create one." %}</p>
|
||||
<a class="btn btn-primary mt-4" href="{% url 'users:forgot_password' %}">{% translate "Request a new link" %}</a>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user