misc: use the django authentication system

This commit is contained in:
2023-11-20 12:24:23 +01:00
parent f3335116e2
commit f608592267
5 changed files with 42 additions and 0 deletions

View File

@ -68,6 +68,7 @@ Usefull context:
<div class="navbar-end">
{% block top-nav-tools %}
{% endblock %}
{% block top-nav-end %}
<div class="navbar-item">
<form action="{% url 'page-list' %}" method="GET">
@ -81,6 +82,12 @@ Usefull context:
</form>
</div>
{% endblock %}
{% if user.is_authenticated %}
<div class="navbar-item">
<a>{{ user.username }}</a> &nbsp; <a href="{% url 'logout' %}"> <i class="fa fa-power-off"></i></a>
</div>
{% endif %}
</div>
</div>
</div>

View File

@ -0,0 +1,20 @@
{% extends "aircox/base.html" %}
{% load i18n aircox %}
{% block main %}
<h2>{% trans "Log in" %}</h2>
<br/>
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<br/>
<button type="submit">{% trans "Log in" %}</button>
<input type="hidden" name="next" value="{{ next }}">
</form>
{{ block.super }}
{% endblock %}

View File

@ -0,0 +1,12 @@
import pytest
from django.urls import reverse
@pytest.mark.django_db()
def test_authenticate(user, client, program):
r = client.get(reverse("login"))
assert r.status_code == 200
assert b"id_username" in r.content
r = client.post(reverse("login"), kwargs={"username": "foo", "password": "bar"})
assert b"errorlist" in r.content
assert client.login(username="user1", password="bar")