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 from django.urls import include, path
import django.contrib.auth.views as dj_auth_views import django.contrib.auth.views as dj_auth_views
from .views import login, logout from .views import logout
app_name = "accounts" app_name = "accounts"
......
from django.shortcuts import render, redirect 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 @login_required
def logout(req): def logout(req):
auth_logout(req) auth_logout(req)
return redirect("home:home") return redirect("home")
...@@ -40,6 +40,11 @@ ...@@ -40,6 +40,11 @@
class={% if slug == "faq" %}"current"{% else %}"internal"{% endif %}> class={% if slug == "faq" %}"current"{% else %}"internal"{% endif %}>
FAQ FAQ
</a> </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> </nav>
<main> <main>
...@@ -65,4 +70,4 @@ ...@@ -65,4 +70,4 @@
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
{% 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.contrib.sitemaps.views import sitemap
from django.views.generic import RedirectView from django.views.generic import RedirectView
from django.urls import path from django.urls import path, include
from . import views from . import views
sitemaps = {"static_pages": views.StaticViewSitemap} sitemaps = {"static_pages": views.StaticViewSitemap}
...@@ -15,4 +15,5 @@ urlpatterns = [ ...@@ -15,4 +15,5 @@ urlpatterns = [
'sitemap.xml', sitemap, {'sitemaps': sitemaps}, 'sitemap.xml', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap' name='django.contrib.sitemaps.views.sitemap'
), ),
] path('accounts/', include("accounts.urls")),
\ No newline at end of file ]
...@@ -38,7 +38,8 @@ INSTALLED_APPS = [ ...@@ -38,7 +38,8 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.sitemaps', 'django.contrib.sitemaps',
'home.apps.HomeConfig', 'home.apps.HomeConfig',
'accounts',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
...@@ -82,6 +83,9 @@ DATABASES = { ...@@ -82,6 +83,9 @@ DATABASES = {
} }
} }
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
# Password validation # Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators # 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