Commit 83cd23e8 authored by Claude Paroz's avatar Claude Paroz

Add a proper logout view

parent 7d8af101
from django.conf import settings
from django.contrib.auth import login, authenticate, logout
from django.contrib.auth import login, authenticate
from django.contrib import messages
from django.http import HttpResponseRedirect, Http404
from django.shortcuts import render
......@@ -49,11 +49,7 @@ def site_login(request):
if request.POST.get('referer', None):
referer = request.POST['referer']
if 'logout' in request.POST and request.POST['logout']:
logout(request)
messages.success(request, _("You have been logged out."))
return redirect(referer)
elif 'username' in request.POST:
if 'username' in request.POST:
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
......
......@@ -2,6 +2,7 @@ from django.conf.urls import include, url
from django.conf import settings
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.views.decorators.http import require_POST
from django.views.generic import TemplateView
from django.views.static import serve
......@@ -19,6 +20,9 @@ urlpatterns = [
url(r'^login/$',
common_views.site_login,
name='login'),
url(r'^logout/$',
require_POST(auth_views.LogoutView.as_view()),
name='logout'),
url(r'^register/$',
common_views.site_register,
name='register'),
......
......@@ -4,9 +4,10 @@
<div class="row">
<div class="col-sm-12">
<a class="btn btn-link no-decoration" href="{% url 'person_detail_username' user.username %}">{% trans 'User Settings' %}</a>
<form action="{% url 'login' %}" method="post" class="form">
<form action="{% url 'logout' %}" method="post" class="form">
{% csrf_token %}
<input type="hidden" name="logout" value="1">
<input type="hidden" name="next" value="{{ request.path }}">
<div class="form-group">
<button type="submit" class="btn btn-link">{% trans 'Log out' %}</button>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment