summaryrefslogtreecommitdiff
path: root/docs/topics/auth
diff options
context:
space:
mode:
authorJon Janzen <jon@jonjanzen.com>2023-02-13 18:24:35 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-07 13:11:22 +0100
commite846c5e7246a0ffbe5dcf07a2b6c7c2a47537eb3 (patch)
treed86cad38a58734387b5142b6d5d90d0b90d2f7f2 /docs/topics/auth
parente83a88566a71a2353cebc35992c110be0f8628af (diff)
Fixed #31920 -- Made AuthenticationMiddleware add request.auser().
Diffstat (limited to 'docs/topics/auth')
-rw-r--r--docs/topics/auth/default.txt15
1 files changed, 15 insertions, 0 deletions
diff --git a/docs/topics/auth/default.txt b/docs/topics/auth/default.txt
index a93201fb09..c705abcb6b 100644
--- a/docs/topics/auth/default.txt
+++ b/docs/topics/auth/default.txt
@@ -368,6 +368,7 @@ Django uses :doc:`sessions </topics/http/sessions>` and middleware to hook the
authentication system into :class:`request objects <django.http.HttpRequest>`.
These provide a :attr:`request.user <django.http.HttpRequest.user>` attribute
+and a :meth:`request.auser <django.http.HttpRequest.auser>` async method
on every request which represents the current user. If the current user has not
logged in, this attribute will be set to an instance
of :class:`~django.contrib.auth.models.AnonymousUser`, otherwise it will be an
@@ -383,6 +384,20 @@ You can tell them apart with
# Do something for anonymous users.
...
+Or in an asynchronous view::
+
+ user = await request.auser()
+ if user.is_authenticated:
+ # Do something for authenticated users.
+ ...
+ else:
+ # Do something for anonymous users.
+ ...
+
+.. versionchanged:: 5.0
+
+ The :meth:`.HttpRequest.auser` method was added.
+
.. _how-to-log-a-user-in:
How to log a user in