diff --git a/app/keys_home/templates/keys_home/base.html b/app/keys_home/templates/keys_home/base.html index d0117fecc2c008e5e908f80af8ba03c33d84ccdc..6248e76dfac3579571add2d5d7efd1f8277c4320 100644 --- a/app/keys_home/templates/keys_home/base.html +++ b/app/keys_home/templates/keys_home/base.html @@ -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> diff --git a/app/keys_home/urls.py b/app/keys_home/urls.py index 3dc3b54a652e881fd1b7ec186300a8bf8ded4c19..8ee6e82d075c2fb7421b0c37e27b358dee21da73 100644 --- a/app/keys_home/urls.py +++ b/app/keys_home/urls.py @@ -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'), ] diff --git a/app/keys_home/views.py b/app/keys_home/views.py index 0e707816c51d800517fb5e4c32463ef054931ca3..d60fb0bc17707740b89458f2ca9d4d9bb957a24a 100644 --- a/app/keys_home/views.py +++ b/app/keys_home/views.py @@ -1,6 +1,14 @@ -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"))