Django

Code

Ticket #903 (closed: fixed)

Opened 4 years ago

Last modified 1 year ago

change login_required

Reported by: Dagur Assigned to: adrian
Milestone: Component: Authentication
Version: SVN Keywords: decorators login_required login_url
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

Description

The way it is now the login_required decorator only redirects to /accounts/login

I want to be able to change this so I don't have to change my mod_python settings just to make /accounts urls handled by Django.

Attachments

patch_login_required.diff (3.6 kB) - added by vbmendes on 02/19/09 07:38:47.
Adds login_url parameter for login_required decorator and redirect_field_name parameter for permission_required decorator.

Change History

11/26/05 01:20:08 changed by adrian

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

(In [1440]) Fixed #903 -- Added login_url argument to user_passes_test view decorator. Didn't add it to login_required decorator because that would turn login_required into a callable decorator, which would break backwards compatibility.

11/26/05 01:21:34 changed by adrian

I added a login_url argument to the user_passes_test view decorator. See the new docs at http://www.djangoproject.com/documentation/authentication/#limiting-access-to-logged-in-users-that-pass-a-test .

11/26/05 05:20:53 changed by Dagur

why is backwards compatibility an issue? :-/

06/15/06 10:41:22 changed by umbrae@gmail.com

  • status changed from closed to reopened.
  • resolution deleted.

This doesn't actually fix the problem with login_required.

As a previous user suggested somewhere else, perhaps a different approach that would save backwards compatibility would be to allow LOGIN_URL to be settable in settings.py.

For now, the best workaround would be to create your own decorator:

 from django.contrib.auth.decorators import user_passes_test
 login_needed = user_passes_test(lambda u: not u.is_anonymous(), login_url='/login/')

A fix should still be looked into however - it works as a workaround, but shouldn't be a hard and fast solution.

08/12/06 00:24:58 changed by adrian

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

If the current behavior is an issue, see the comment by umbrae@gmail.com for a workaround.

02/19/09 07:37:02 changed by vbmendes

  • status changed from closed to reopened.
  • component changed from Core framework to Authentication.
  • needs_tests set to 1.
  • version set to SVN.
  • keywords set to decorators login_required login_url.
  • has_patch set to 1.
  • resolution deleted.

I am reopening this ticket becouse I don't see a reason for not adding login_url parameter for login_required decorator. It is already callable, and already takes parameters (redirect_field_name). So, why not adding the login_url parameter?

I also realised that permission_required decorator doesn't accepts redirect_field_name. So, why not make a pattern for the acceptable parameters for the auth decorators?

I wrote a patch to create this pattern. Now all three decorators accepts login_url and redirect_field_name. permission_required requires an extra parameter (perm) and user_passes_test requires test_func.

In login_required, the parameters order is different becouse of backwards compatibility, since you can do this expecting 'redirect_to' to be the redirect_field_name:

@login_required('redirect_to') def my_view(request):

# ...

02/19/09 07:38:47 changed by vbmendes

  • attachment patch_login_required.diff added.

Adds login_url parameter for login_required decorator and redirect_field_name parameter for permission_required decorator.

02/25/09 13:58:49 changed by jacob

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

Please don't reopen tickets closed by a committer. The correct way to revisit issues is to take it up on django-dev.


Add/Change #903 (change login_required)




Change Properties
Action