Skip to content
Snippets Groups Projects
Verified Commit b980dfd4 authored by Frank Sauerburger's avatar Frank Sauerburger
Browse files

Add logout route

parent 1238f509
No related branches found
No related tags found
1 merge request!12Resolve "Login/Logout"
Pipeline #7629 waiting for manual action
......@@ -42,16 +42,25 @@
<i class="fas fa-network-wired"></i> PKI
</a>
</li>
{% if request.user.is_anonymous %}
<li class="navbar-login">
{% if request.user.is_anonymous %}
<a href="">
<i class="fas fa-sign-in-alt"></i> Login
</a>
{% else %}
<a href="">
<i class="fas fa-user"></i> {{ request.user.username }}
</a>
{% endif %}
<a href="{% url 'login' %}">
<i class="fas fa-sign-in-alt"></i> Login
</a>
</li>
{% else %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbar-user" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ request.user }}
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbar-user">
{% if request.user.is_staff %}
<a class="dropdown-item" href="/admin">Admin</a>
{% endif %}
<a class="dropdown-item" href="/logout">Logout</a>
</div>
</li>
{% endif %}
</li>
</ul>
</div>
......
......@@ -20,5 +20,6 @@ from . import views
urlpatterns = [
path("", views.home, name="home"),
path('login/', auth_views.LoginView.as_view()),
path('login/', auth_views.LoginView.as_view(), name="login"),
path('logout/', views.logout, name='logout'),
]
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.urls import reverse
from django.views.decorators.http import require_safe
import django.contrib.auth as auth
@require_safe
def home(request):
return render(request, "keys_home/home.html")
def logout(request):
if request.user.is_authenticated:
auth.logout(request)
return redirect(reverse("home"))
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