#31288: New ReplaceAuthMiddleware feature
-------------------------------------+-------------------------------------
               Reporter:  TheoHd     |          Owner:  nobody
                   Type:  New        |         Status:  new
  feature                            |
              Component:             |        Version:  3.0
  contrib.auth                       |       Keywords:  django contrib auth
               Severity:  Normal     |  middleware ReplaceAuthMiddleware
           Triage Stage:             |  3.0 ease of use for big projects
  Unreviewed                         |      Has patch:  0
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31288>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.9611f498b772da9a54b8db73a0b3a585%40djangoproject.com.

Reply via email to