Django

Code

Ticket #3185 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

Allow django.contrib.auth's LOGIN_URL, LOGOUT_URL and ACCOUNT_URL to be set in settings.py

Reported by: Vasily Sulatskov <redvasily@gmail.com> Assigned to: adrian
Milestone: Component: Contrib apps
Version: SVN Keywords:
Cc: Vasily, Sulatskov, <redvasily@gmail.com>, jonasvp@gmx.de Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description

Currently it's impossible to change LOGIN_URL varaible which is used in django.contrib.auth

I found this discussion on mailing list.

Adrian Holovaty said that LOGIN_URL should be made configurable. I made tiny patch to make it possible to specify LOGIN_URL in site settings.py module. This patch works at least for me and doesn't break anything else (as far as I know).

Attachments

login_url.diff (0.6 kB) - added by Vasily Sulatskov <redvasily@gmail.com> on 12/24/06 05:17:23.
login_url2.diff (1.8 kB) - added by Vasily Sulatskov <redvasily@gmail.com> on 12/29/06 07:22:02.
login_url3.diff (1.6 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 01/17/07 19:47:12.
using getattr instead of try/except
3185_docs.patch (2.8 kB) - added by Marc Fargas <telenieko@telenieko.com> on 01/18/07 16:21:35.
Documentation for this ticket.
3185.diff (4.3 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 01/19/07 11:41:39.
code and docs in one patch
3185_2.diff (4.3 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 01/19/07 11:48:34.
use relative link, as mentioned in #3333
3185_3.diff (6.6 kB) - added by Vasily Sulatskov <redvasily@gmail.com> on 02/02/07 12:02:41.
Added LOGOUT_URL variable to auth/init.py. Modified comments app to use it.
3185_4.diff (6.7 kB) - added by Vasily Sulatskov <redvasily@gmail.com> on 02/23/07 12:14:08.
Uber patch. Everything included
login_url.patch (10.4 kB) - added by Collin Grady <cgrady@the-magi.us> on 04/24/07 21:31:36.

Change History

12/24/06 05:17:23 changed by Vasily Sulatskov <redvasily@gmail.com>

  • attachment login_url.diff added.

12/24/06 05:21:44 changed by Vasily Sulatskov <redvasily@gmail.com>

  • summary changed from Possibility of overriding django.contrib.auth.LOGIN_URL in settings.py to [patch]Possibility of overriding django.contrib.auth.LOGIN_URL in settings.py.

12/24/06 10:45:53 changed by Gary Wilson <gary.wilson@gmail.com>

While we're at it we should go ahead and make the profile URL configurable too, which is currently hardcoded in the contrib.auth.views.login view.

12/29/06 07:21:14 changed by Vasily Sulatskov <redvasily@gmail.com>

  • cc set to Vasily, Sulatskov, <redvasily@gmail.com>.
  • summary changed from [patch]Possibility of overriding django.contrib.auth.LOGIN_URL in settings.py to [patch]Possibility of overriding django.contrib.auth.LOGIN_URL and account URL used in auth.views,login() in settings.py.

I noticed that I myself use custom version of django.contrib.auth.views.login() that used different account URL, so I made it configurable also.

Patch: login_url2.diff

12/29/06 07:22:02 changed by Vasily Sulatskov <redvasily@gmail.com>

  • attachment login_url2.diff added.

12/29/06 07:22:55 changed by Vasily Sulatskov <redvasily@gmail.com>

  • summary changed from [patch]Possibility of overriding django.contrib.auth.LOGIN_URL and account URL used in auth.views,login() in settings.py to [patch]Possibility of overriding django.contrib.auth.LOGIN_URL and account URL used in auth.views.login() in settings.py.

01/17/07 19:47:12 changed by Gary Wilson <gary.wilson@gmail.com>

  • attachment login_url3.diff added.

using getattr instead of try/except

01/17/07 19:54:46 changed by Gary Wilson <gary.wilson@gmail.com>

  • keywords deleted.
  • needs_docs set to 1.
  • summary changed from [patch]Possibility of overriding django.contrib.auth.LOGIN_URL and account URL used in auth.views.login() in settings.py to Allow django.contrib.auth's LOGIN_URL and ACCOUNT_URL to be set in settings.py.
  • stage changed from Unreviewed to Accepted.

Adrian gave the ok in the thread mentioned in the ticket description.

01/18/07 16:21:35 changed by Marc Fargas <telenieko@telenieko.com>

  • attachment 3185_docs.patch added.

Documentation for this ticket.

(follow-up: ↓ 8 ) 01/18/07 16:23:47 changed by Marc Fargas <telenieko@telenieko.com>

  • needs_docs deleted.

Documentation added, please take one thing in account: I set a link to @login_decorator twice (in the ACCOUNT_URL and LOGIN_URL sections) thus the line ".. _@login_decorator" is at the bottom of the file, I have no idea if this works, and this silly PC doesn't want to download docutils now to let me check... so please take this into account before appliying!

Also, I have no idea if the "@" can be there on the link... ;)

Hope I didn't miss anything to change.

01/19/07 10:41:52 changed by Vasily Sulatskov <redvasily@gmail.com>

Some more advocacy for this ticket: in this thread Why I'm giving up on Django one of the reasons for giving Django up was:

"This is a biggie for me. I can't believe that the authentication module forces you to use hard coded urls for login/logout pages -- that's just maddening!"

Ahd that's what this patch fixes.

(in reply to: ↑ 6 ) 01/19/07 11:41:01 changed by Gary Wilson <gary.wilson@gmail.com>

  • stage changed from Accepted to Ready for checkin.

Replying to Marc Fargas <telenieko@telenieko.com>:

Documentation added, please take one thing in account: I set a link to @login_decorator twice (in the ACCOUNT_URL and LOGIN_URL sections) thus the line ".. _@login_decorator" is at the bottom of the file, I have no idea if this works, and this silly PC doesn't want to download docutils now to let me check... so please take this into account before appliying! Also, I have no idea if the "@" can be there on the link... ;)

Seems to work for me. Thanks for the patch.

01/19/07 11:41:39 changed by Gary Wilson <gary.wilson@gmail.com>

  • attachment 3185.diff added.

code and docs in one patch

01/19/07 11:48:34 changed by Gary Wilson <gary.wilson@gmail.com>

  • attachment 3185_2.diff added.

use relative link, as mentioned in #3333

01/31/07 16:52:17 changed by Gary Wilson <gary.wilson@gmail.com>

  • needs_better_patch set to 1.
  • stage changed from Ready for checkin to Accepted.

After playing around with contrib.comments, it appears that we should probably have a LOGOUT_URL also since in the comment app's form.html template there is a hardcoded /accounts/logout/. This would be simple enough to add, that we should just add it to this ticket instead of creating a new one.

01/31/07 18:00:01 changed by Marc Fargas <telenieko@telenieko.com>

  • needs_docs set to 1.
  • summary changed from Allow django.contrib.auth's LOGIN_URL and ACCOUNT_URL to be set in settings.py to Allow django.contrib.auth's LOGIN_URL, LOGOUT_URL and ACCOUNT_URL to be set in settings.py.

+1 Adding need documentation to document the settings.LOGOUT_URL when the patch comes in.

02/02/07 12:02:41 changed by Vasily Sulatskov <redvasily@gmail.com>

  • attachment 3185_3.diff added.

Added LOGOUT_URL variable to auth/init.py. Modified comments app to use it.

02/02/07 12:05:52 changed by Vasily Sulatskov <redvasily@gmail.com>

I didn't test 3185_3.diff because I don't use comments app myself. But changes were obvious so perhaps patch will work fine.

02/02/07 18:32:10 changed by anonymous

  • needs_better_patch deleted.
  • stage changed from Accepted to Ready for checkin.
  • needs_docs deleted.

02/02/07 18:32:32 changed by anonymous

Thanks for the patch Vasily.

02/02/07 18:33:49 changed by Gary Wilson <gary.wilson@gmail.com>

The above comments were made by me :)

02/17/07 15:56:44 changed by Jannis Leidel <jl@websushi.org>

+1 from me

02/22/07 04:06:40 changed by anonymous

  • cc changed from Vasily, Sulatskov, <redvasily@gmail.com> to Vasily, Sulatskov, <redvasily@gmail.com>, jonasvp@gmx.de.

02/23/07 12:06:19 changed by jacob

  • needs_better_patch set to 1.

It's not clear to me which of these patches should be applied, and in which order. Can one of the patch authors upload an über-patch that does it all in one fell swoop?

02/23/07 12:14:08 changed by Vasily Sulatskov <redvasily@gmail.com>

  • attachment 3185_4.diff added.

Uber patch. Everything included

02/23/07 12:20:08 changed by Vasily Sulatskov <redvasily@gmail.com>

I think that ACCOUNT_URL variable name is misleading, because it's not necessary to redirect user after successful login to account page. So I changed it to POSTLOGIN_REDIRECT_URL in 3185_4.diff.

3185_4.diff contains all needed changes.

02/24/07 10:10:10 changed by Marc Fargas <telenieko@telenieko.com>

  • needs_better_patch deleted.

Removing "needs better patch" as Vasily uploaded what jacob requested ;)

03/12/07 06:25:10 changed by mtredinnick

  • needs_better_patch set to 1.
  • stage changed from Ready for checkin to Accepted.

The most recent patch still has a few subtle problems:

  1. Anything that is configurable should always be read from settings, not shoved in as a constant into some other module (it's not a constant any longer, after all). I realise LOGIN_URL is already a constant in the auth module, but that now becomes a proxy for the value from settings for backwards compatibility reasons. Everything else comes straight out of settings (including all current internal uses of LOGIN_URL).
  1. We should not be reading anything from settings at import time; only at execution time. The reason for this is manually configured settings. The developer needs to be able to import the necessary modules and then call settings.configure(). The current code reads from settings at import time and so will raise a configuration error. This problem exists in other parts of Django as well, but that's not a reason to perpetuate the problem.

04/24/07 21:31:36 changed by Collin Grady <cgrady@the-magi.us>

  • attachment login_url.patch added.

04/24/07 21:34:45 changed by Collin Grady <cgrady@the-magi.us>

Took a stab at fixing the patch based on comments, as I would like this as well :)

04/25/07 03:49:58 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [5072]) Fixed #3185 -- Made values for login, logout and post-login redirect URLs configurable. This is a combined patch from Vasily Sulatskov, Marc Fargas and Collin Grady.


Add/Change #3185 (Allow django.contrib.auth's LOGIN_URL, LOGOUT_URL and ACCOUNT_URL to be set in settings.py)




Change Properties
Action