Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#10460 closed (fixed)

Better redirect for logout view of Authentication

Reported by: Felipe 'chronos' Prenholato Owned by: nobody
Component: contrib.auth Version: master
Severity: Keywords: Authentication, login, logout, redirect, kkmp2
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This patch make logout view use same style of login view to redirect user to any page, but maintain compatibility with current mode.
With this patch you can use some url like:

/logout/?next=/page-x/

With single code in urls.py:

(r'^logout/$', 'django.contrib.auth.views.logout'),

Attachments (3)

views.py.diff (1.2 KB) - added by Felipe 'chronos' Prenholato 8 years ago.
Patch to make logout redirects like login view.
fixed-auth-logout-with-redirect.diff (3.6 KB) - added by Felipe 'chronos' Prenholato 8 years ago.
logout redirects like login view, with tests
auth-logout-with-redirect.diff (5.5 KB) - added by steingrd 8 years ago.
logout view redirects like login view, with tests

Download all attachments as: .zip

Change History (12)

Changed 8 years ago by Felipe 'chronos' Prenholato

Attachment: views.py.diff added

Patch to make logout redirects like login view.

comment:1 Changed 8 years ago by Chris Beaven

Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 8 years ago by Jacob

milestone: 1.1
Triage Stage: Design decision neededAccepted

comment:3 Changed 8 years ago by Alex Gaynor

Needs tests: unset

comment:4 Changed 8 years ago by steingrd

I've attempted to write some tests for the first patch. My patch includes the changes from the views.py.diff patch.

The tests do not cover the case where the next_page option is specified in the urlconf. The reason is that django.contrib.auth.urls is used, this urlconf does not a contain such an entry. The tests uses django.contrib.auth.SESSION_KEY in client.request.session to check if a user is logged in.

If someone could confirm that the patch is going in the right direction, I'll make an attempt to write documentation as well.

Changed 8 years ago by Felipe 'chronos' Prenholato

logout redirects like login view, with tests

comment:5 Changed 8 years ago by Felipe 'chronos' Prenholato

Needs tests: set

I have fixed a wrong variable name in path. I fixed it here a bit after send path but miss to send updated views.py.diff file.
I include in this last changes of steingrd but not tested with test classes because don't know how, so, someone need to do it.

Changed 8 years ago by steingrd

logout view redirects like login view, with tests

comment:6 Changed 8 years ago by steingrd

Needs tests: unset

Since my initial tests did not catch the bug pointed out by Chronos, I made a second attempt. This time I added a urlconf for the tests. In addition to an regressiontest for the case where the initial patch used the wrong variable name, I've added a test for the next_page keyword argument.

comment:7 Changed 8 years ago by Kevin Kubasik

Keywords: kkmp2 added

comment:8 Changed 8 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [10332]) Fixed #10460: the logout view can now redirect like the rest of the auth views. Thanks, chronos and steingrd.

comment:9 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top