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_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

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

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

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

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

Loading…
Cancel
Save