﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31288	New ReplaceAuthMiddleware feature.	Théo Huchard	Théo Huchard	"Hello,

I have developped a new feature as a middleware that I am using for a personal project. I think it could be a great implementation for Django.

Here is an example of usage in the {{{settings.py}}} file:

{{{
#!div style=""font-size: 100%""
Code highlighting:
  {{{#!python
REPLACE_URL_IF_UNLOGGED = {
    ""replace"": [""index"", ""logout""],
    ""by"": ""/login""
}
REPLACE_URL_IF_LOGGED = {
    ""replace"": [""login""],
    ""by"": ""/""
}
  }}}
}}}

The goal here is to redirect the user if he is logged or unlogged directly from the replace URL. 

In my example, if the user is unlogged and trying to access the URL that was defined in {{{urls.py}}} like below: 

{{{
#!div style=""font-size: 100%""
Code highlighting:
  {{{#!python
urlpatterns = [
    path('', index, name=""index""),
    path('login', login.view, name='login'),
    path('logout', logout.execute, name='logout')
]
  }}}
}}}

...he will automatically be redirected to the {{{""by""}}} element, just by checking if the user is logged or not.

So in this example, if the user is actually logged in and tries to access the {{{login}}} URL defined in {{{urls.py}}} he'll be redirected to the {{{index}}} URL.
And if the user is unlogged and try to access the {{{index}}} or {{{logout}}} URL, he'll be redirected to the {{{login}}} URL.

I thing that it might be a nice addition to the example in the doc:


{{{
#!div style=""font-size: 100%""
Code highlighting:
  {{{#!python
from django.contrib.auth.decorators import login_required

@login_required
def my_view(request):
    ...
  }}}
}}}

...since it can ease URL redirection directly from the {{{settings.py}}} file instead of using decorator.



"	New feature	closed	contrib.auth	dev	Normal	wontfix	django contrib auth middleware ReplaceAuthMiddleware 3.0 ease of use for big projects		Unreviewed	0	0	0	0	0	0
