feat: add e-mail change with confirmation and undo

Page at /email asks for the new address and the current password (shared failure counter with the password page, five requests per hour) and mails a one-hour confirmation link to the new address. Confirming writes the address and mails the old address a 24-hour undo link; undoing restores it, ends every session of the user and notifies the Admin (ADMIN_NOTIFY_EMAIL). Link pages show on GET and apply on POST; tokens are stored only as hashes, single use, and are blanked from every log line. New table owned by profile, German text, tests; review findings logged in the plan.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FocPJ75XPma7TcuYEMy8zm
This commit is contained in:
Ebbe Baß
2026-10-19 10:05:41 +02:00
co-authored by Claude Sonnet 5.5
parent 3fd8f27127
commit 94c1d39c9d
35 changed files with 1792 additions and 14 deletions
+1 -1
View File
@@ -29,7 +29,7 @@
<dt>{% trans "User name" %}</dt>
<dd>{{ details.username }}</dd>
<dt>{% trans "E-mail address" %}</dt>
<dd>{% if details.mail %}{{ details.mail }}{% else %}&ndash;{% endif %}</dd>
<dd>{% if details.mail %}{{ details.mail }}{% else %}&ndash;{% endif %} <a href="{% url 'email' %}">{% trans "Change e-mail address" %}</a></dd>
</dl>
{% endif %}
<form method="post" action="{% url 'profile' %}" class="card" data-busy-on-submit novalidate>
+41
View File
@@ -0,0 +1,41 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Change e-mail address" %}{% endblock %}
{% block content %}
<h1>{% trans "Change e-mail address" %}</h1>
<p class="lead">{% trans "Announcements and security notices are sent to this address. We send a link to the new address. Your address changes only after you open the link and confirm." %}</p>
{% if throttled %}
<div class="notice" role="alert" tabindex="-1" data-focus-on-load>
<p>{% trans "Too many attempts. Please wait a few minutes." %}</p>
</div>
<p><a class="button" href="{% url 'home' %}">{% trans "Back to the start page" %}</a></p>
{% else %}
{% if form.errors %}
<div class="error-summary" role="alert" tabindex="-1" data-focus-on-load>
<p><strong>{% trans "No link was sent." %}</strong></p>
<ul>
{% for field in form %}{% for error in field.errors %}
<li><a href="#{{ field.id_for_label }}">{{ error }}</a></li>
{% endfor %}{% endfor %}
</ul>
</div>
{% endif %}
{% if current is not None %}
<dl class="card details">
<dt>{% trans "Current e-mail address" %}</dt>
<dd>{% if current %}{{ current }}{% else %}&ndash;{% endif %}</dd>
</dl>
{% endif %}
<form method="post" action="{% url 'email' %}" class="card" data-busy-on-submit novalidate>
{% csrf_token %}
{% trans "New e-mail address" as label %}
{% include "profile/_text_field.html" with field=form.new_email label=label max_length=254 autocomplete="email" input_type="email" required=True %}
{% trans "Current password" as label %}{% trans "We check it before anything is sent." as hint %}
{% include "profile/_field.html" with field=form.current_password label=label hint=hint autocomplete="current-password" %}
<p class="actions">
<button type="submit" class="primary"><span class="spinner" aria-hidden="true"></span>{% trans "Send confirmation link" %}</button>
<a class="button" href="{% url 'profile' %}">{% trans "Cancel" %}</a>
</p>
</form>
{% endif %}
{% endblock %}
@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Address changed again" %}{% endblock %}
{% block content %}
<h1>{% trans "Address changed again" %}</h1>
<div class="notice" role="alert">
<p>{% trans "The e-mail address was changed again since then. Nothing was changed now. If this was not you, contact the administrator." %}</p>
</div>
<p><a class="button" href="{% url 'home' %}">{% trans "Back to the start page" %}</a></p>
{% endblock %}
@@ -0,0 +1,20 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Confirm new e-mail address" %}{% endblock %}
{% block content %}
<h1>{% trans "Confirm new e-mail address" %}</h1>
<p class="lead">{% trans "The e-mail address of your account will change. Nothing changes until you press the button." %}</p>
<dl class="card details">
<dt>{% trans "Current e-mail address" %}</dt>
<dd>{% if change.old_address %}{{ change.old_address }}{% else %}&ndash;{% endif %}</dd>
<dt>{% trans "New e-mail address" %}</dt>
<dd>{{ change.new_address }}</dd>
</dl>
{% if change.old_address %}<p>{% trans "A notice with a way to undo the change is sent to the current address." %}</p>{% endif %}
<form method="post" action="{{ request.path }}" class="card" data-busy-on-submit>
{% csrf_token %}
<p class="actions">
<button type="submit" class="primary"><span class="spinner" aria-hidden="true"></span>{% trans "Confirm change" %}</button>
</p>
</form>
{% endblock %}
@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "E-mail address changed" %}{% endblock %}
{% block content %}
<h1>{% trans "E-mail address changed" %}</h1>
<div class="notice success" role="status">
<p>{% trans "Your e-mail address was changed." %}</p>
</div>
{% if notice %}<p>{% trans "A notice with a way to undo the change was sent to your previous address." %}</p>{% endif %}
<p><a class="button" href="{% url 'home' %}">{% trans "Back to the start page" %}</a></p>
{% endblock %}
@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Link not valid" %}{% endblock %}
{% block content %}
<h1>{% trans "Link not valid" %}</h1>
<div class="notice" role="alert">
<p>{% trans "This link is not valid any more." %}</p>
</div>
<p><a class="button" href="{% url 'home' %}">{% trans "Back to the start page" %}</a></p>
{% endblock %}
+11
View File
@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Confirmation link sent" %}{% endblock %}
{% block content %}
<h1>{% trans "Confirmation link sent" %}</h1>
<div class="notice success" role="status">
<p>{% trans "We sent a link to your new e-mail address. It is valid for one hour." %}</p>
</div>
<p>{% trans "Your address has not changed yet. It changes after you open the link and confirm." %}</p>
<p><a class="button" href="{% url 'profile' %}">{% trans "Back to the profile" %}</a></p>
{% endblock %}
+20
View File
@@ -0,0 +1,20 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Undo e-mail change" %}{% endblock %}
{% block content %}
<h1>{% trans "Undo e-mail change" %}</h1>
<p class="lead">{% trans "The e-mail address of your account was changed. If you did not do this, undo the change now." %}</p>
<dl class="card details">
<dt>{% trans "Previous e-mail address" %}</dt>
<dd>{{ change.old_address }}</dd>
<dt>{% trans "Current e-mail address" %}</dt>
<dd>{{ change.new_address }}</dd>
</dl>
<p>{% trans "Undoing restores the previous address, signs you out on all devices and informs the administrator." %}</p>
<form method="post" action="{{ request.path }}" class="card" data-busy-on-submit>
{% csrf_token %}
<p class="actions">
<button type="submit" class="primary"><span class="spinner" aria-hidden="true"></span>{% trans "Undo change" %}</button>
</p>
</form>
{% endblock %}
@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "E-mail change undone" %}{% endblock %}
{% block content %}
<h1>{% trans "E-mail change undone" %}</h1>
<div class="notice success" role="status">
<p>{% trans "Your previous e-mail address is back. You were signed out on all devices." %}</p>
</div>
<p><strong>{% trans "Someone else may have had access to your account. Please change your password now." %}</strong></p>
<p><a class="button primary" href="{% url 'password' %}">{% trans "Change password" %}</a></p>
{% endblock %}
@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Result unclear" %}{% endblock %}
{% block content %}
<h1>{% trans "Result unclear" %}</h1>
<div class="notice" role="alert">
<p>{% trans "Your e-mail address may have been changed, but the portal could not finish. Please check your profile or contact the administrator." %}</p>
</div>
<p><a class="button" href="{% url 'home' %}">{% trans "Back to the start page" %}</a></p>
{% endblock %}