Add ability to logout

This commit is contained in:
Michael Hall 2018-01-26 21:27:35 -05:00
parent 7cbb96bb09
commit c0bb231734
3 changed files with 22 additions and 7 deletions

View file

@ -49,20 +49,28 @@ form {
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="{% url 'events' %}">Events <span class="sr-only">(current)</span></a>
<li class="nav-item{% if request.resolver_match.url_name == "events" %} active{% endif %}">
<a class="nav-link" href="{% url 'events' %}">Events{% if request.resolver_match.url_name == "events" %} <span class="sr-only">(current)</span>{% endif %}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'teams' %}">Teams</a>
<li class="nav-item{% if request.resolver_match.url_name == "teams" %} active{% endif %}">
<a class="nav-link" href="{% url 'teams' %}">Teams{% if request.resolver_match.url_name == "teams" %} <span class="sr-only">(current)</span>{% endif %}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'places' %}">Places</a>
<li class="nav-item{% if request.resolver_match.url_name == "places" %} active{% endif %}">
<a class="nav-link" href="{% url 'places' %}">Places{% if request.resolver_match.url_name == "places" %} <span class="sr-only">(current)</span>{% endif %}</a>
</li>
</ul>
<ul class="navbar-nav">
{% if request.user.is_authenticated %}
<li class="nav-item"><a class="nav-link">Welcome {{ request.user.username }}</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarUserMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Welcome {{ request.user.username }}
</a>
<div class="dropdown-menu" aria-labelledby="navbarUserMenuLink">
<a class="dropdown-item disabled" href="#">Profile</a>
<a class="dropdown-item" href="{% url 'logout' %}">Logout</a>
</div>
</li>
{% else %}
<li class="nav-item"><a class="nav-link" href="/">Signup or Login</a></li>
{% endif %}

View file

@ -25,6 +25,7 @@ from . import views
urlpatterns = [
path('', views.home, name='home'),
path('admin/', admin.site.urls),
path('logout/', views.logout, name='logout'),
path('searchables/', event_views.searchable_list, name='searchables'),
path('api/places/', event_views.places_list),

View file

@ -1,6 +1,7 @@
from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
from django.contrib.auth import logout as logout_user
from django.shortcuts import render, redirect
from django.http import HttpResponse, JsonResponse
@ -14,6 +15,11 @@ import simplejson
# Create your views here.
def logout(request):
if request.user.is_authenticated:
logout_user(request)
return redirect('home')
def home(request, *args, **kwards):
if request.user.is_authenticated:
user_teams = Team.objects.filter(owner_profile=request.user.profile)