Browse Source

feat: Forum App - 5. Add Logout Endpoint

master
Bobson Lin 2 years ago
parent
commit
c40e27a3f9
5 changed files with 26 additions and 12 deletions
  1. +1
    -0
      community/community/settings.py
  2. +20
    -10
      community/forum/templates/navbar.html
  3. +2
    -2
      community/user_profile/templates/user_profile/login.html
  4. +1
    -0
      community/user_profile/urls.py
  5. +2
    -0
      community/user_profile/views.py

+ 1
- 0
community/community/settings.py View File

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

+ 20
- 10
community/forum/templates/navbar.html View File

@ -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>


+ 2
- 2
community/user_profile/templates/user_profile/login.html View File

@ -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>


+ 1
- 0
community/user_profile/urls.py View File

@ -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')
]

+ 2
- 0
community/user_profile/views.py View File

@ -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