feat: Forum App - 5. Add Logout Endpoint

master
Bobson Lin 5 years ago
parent 05dfeb8ee4
commit c40e27a3f9

@ -124,3 +124,4 @@ STATIC_URL = '/static/'
LOGIN_URL = '/login/' LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/' LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

@ -23,7 +23,7 @@
<div id="navbarBasicExample" class="navbar-menu is-active"> <div id="navbarBasicExample" class="navbar-menu is-active">
<div class="navbar-start"> <div class="navbar-start">
<a class="navbar-item"> <a class="navbar-item" href="{% url 'index' %}">
Home Home
</a> </a>
@ -34,15 +34,25 @@
<div class="navbar-end"> <div class="navbar-end">
<div class="navbar-item"> <div class="navbar-item">
<p class="has-margin-right-10">Welcome, {{ user }}</p>
<div class="buttons"> {% if user.is_authenticated %}
<a class="button is-primary" href="{% url 'register' %}"> <p class="has-margin-right-10">Hello, {{ user.username }}</p>
<strong>Sign up</strong> <div class="buttons">
</a> <a class="button is-light" href="{% url 'logout' %}">
<a class="button is-light" href="{% url 'login' %}"> Log out
Log in </a>
</a> </div>
</div> {% else %}
<div class="buttons">
<a class="button is-primary" href="{% url 'register' %}">
<strong>Sign up</strong>
</a>
<a class="button is-light" href="{% url 'login' %}">
Log in
</a>
</div>
{% endif %}
</div> </div>
</div> </div>
</div> </div>

@ -19,7 +19,6 @@
<div class="control"> <div class="control">
{{ form.username }} {{ form.username }}
</div> </div>
{{ form.username.errors }}
</div> </div>
<div class="field"> <div class="field">
@ -27,9 +26,10 @@
<div class="control"> <div class="control">
{{ form.password }} {{ form.password }}
</div> </div>
{{ form.username.errors }}
</div> </div>
{{ form.non_field_errors }}
<div class="control"> <div class="control">
<button class="button is-primary">Login</button> <button class="button is-primary">Login</button>
</div> </div>

@ -9,5 +9,6 @@ urlpatterns = [
auth_view.LoginView.as_view(template_name='user_profile/login.html', auth_view.LoginView.as_view(template_name='user_profile/login.html',
authentication_form=ExtendedAuthenticationForm), authentication_form=ExtendedAuthenticationForm),
name='login'), name='login'),
path('logout', auth_view.LogoutView.as_view(), name='logout'),
path('profile', views.profile, name='profile') path('profile', views.profile, name='profile')
] ]

@ -1,5 +1,6 @@
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from .forms import ExtendedUserCreationForm from .forms import ExtendedUserCreationForm
@ -19,5 +20,6 @@ def register(request):
return render(request, 'user_profile/register.html', {'form': form}) return render(request, 'user_profile/register.html', {'form': form})
@login_required
def profile(request): def profile(request):
return render(request, 'user_profile/profile.html') return render(request, 'user_profile/profile.html')

Loading…
Cancel
Save