Skip to content
Snippets Groups Projects
Commit 43a36506 authored by Quentin VERMANDE's avatar Quentin VERMANDE
Browse files

fixed logout view and templates

parent 62d10782
No related branches found
No related tags found
No related merge requests found
from django.urls import include, path
import django.contrib.auth.views as dj_auth_views
from .views import login, logout
from .views import logout
app_name = "accounts"
......
from django.shortcuts import render, redirect
from django.contrib.auth import logout as auth_logout
from django.contrib.auth.decorators import login_required
@login_required
def logout(req):
auth_logout(req)
return redirect("home:home")
return redirect("home")
......@@ -40,6 +40,11 @@
class={% if slug == "faq" %}"current"{% else %}"internal"{% endif %}>
FAQ
</a>
{% if request.user.is_authenticated %}
<a class="logout" href="{% url "accounts:logout" %}">Déconnexion</a>
{% else %}
<a class="login" href="{% url "accounts:login" %}?next={{ request.get_full_path }}">Connexion</a>
{% endif %}
</nav>
<main>
......@@ -65,4 +70,4 @@
</footer>
</body>
</html>
\ No newline at end of file
</html>
{% extends "base.html" %}
{% block "content" %}
<div id="content-area">
{% if form.errors %}
<p>Login ou mot de passe incorrect</p>
{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p>Accès non autorisé.</p>
{% else %}
<p>Merci de vous connecter.</p>
{% endif %}
{% endif %}
<form method="post" action="{% url "accounts:login" %}?next={{ next|urlencode }}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="connexion" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
</div>
{% endblock %}
from django.contrib.sitemaps.views import sitemap
from django.views.generic import RedirectView
from django.urls import path
from django.urls import path, include
from . import views
sitemaps = {"static_pages": views.StaticViewSitemap}
......@@ -15,4 +15,5 @@ urlpatterns = [
'sitemap.xml', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'
),
]
\ No newline at end of file
path('accounts/', include("accounts.urls")),
]
......@@ -38,7 +38,8 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
'home.apps.HomeConfig',
'home.apps.HomeConfig',
'accounts',
]
MIDDLEWARE = [
......@@ -82,6 +83,9 @@ DATABASES = {
}
}
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment