Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
f7e91cac
Kaydet (Commit)
f7e91cac
authored
Agu 24, 2016
tarafından
Berker Peksag
Kaydeden (comit)
Tim Graham
Eyl 27, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27053 -- Documented contrib.auth.get_user().
üst
419b6ec7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletion
+43
-1
auth.txt
docs/ref/contrib/auth.txt
+23
-0
test_basic.py
tests/auth_tests/test_basic.py
+20
-1
No files found.
docs/ref/contrib/auth.txt
Dosyayı görüntüle @
f7e91cac
...
@@ -682,3 +682,26 @@ The following backends are available in :mod:`django.contrib.auth.backends`:
...
@@ -682,3 +682,26 @@ The following backends are available in :mod:`django.contrib.auth.backends`:
An :class:`~django.apps.AppConfig` for use if you :ref:`aren't using
An :class:`~django.apps.AppConfig` for use if you :ref:`aren't using
<using-auth-without-models>` any of the built-in ``contrib.auth`` models.
<using-auth-without-models>` any of the built-in ``contrib.auth`` models.
Utility functions
=================
.. currentmodule:: django.contrib.auth
.. function:: get_user(request)
Returns the user model instance associated with the given ``request``’s
session.
It checks if the authentication backend stored in the session is present in
:setting:`AUTHENTICATION_BACKENDS`. If so, it uses the backend's
``get_user()`` method to retrieve the user model instance and then verifies
the session by calling the user model's
:meth:`~django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash`
method.
Returns an instance of :class:`~django.contrib.auth.models.AnonymousUser`
if the authentication backend stored in the session is no longer in
:setting:`AUTHENTICATION_BACKENDS`, if a user isn't returned by the
backend's ``get_user()`` method, or if the session auth hash doesn't
validate.
tests/auth_tests/test_basic.py
Dosyayı görüntüle @
f7e91cac
...
@@ -3,10 +3,11 @@ from __future__ import unicode_literals
...
@@ -3,10 +3,11 @@ from __future__ import unicode_literals
import
warnings
import
warnings
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth
import
get_user
,
get_user
_model
from
django.contrib.auth.models
import
AnonymousUser
,
User
from
django.contrib.auth.models
import
AnonymousUser
,
User
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.exceptions
import
ImproperlyConfigured
from
django.db
import
IntegrityError
from
django.db
import
IntegrityError
from
django.http
import
HttpRequest
from
django.test
import
TestCase
,
override_settings
from
django.test
import
TestCase
,
override_settings
from
django.utils
import
translation
from
django.utils
import
translation
...
@@ -158,3 +159,21 @@ class BasicTestCase(TestCase):
...
@@ -158,3 +159,21 @@ class BasicTestCase(TestCase):
with
translation
.
override
(
'es'
):
with
translation
.
override
(
'es'
):
self
.
assertEqual
(
User
.
_meta
.
verbose_name
,
'usuario'
)
self
.
assertEqual
(
User
.
_meta
.
verbose_name
,
'usuario'
)
self
.
assertEqual
(
User
.
_meta
.
verbose_name_plural
,
'usuarios'
)
self
.
assertEqual
(
User
.
_meta
.
verbose_name_plural
,
'usuarios'
)
class
TestGetUser
(
TestCase
):
def
test_get_user_anonymous
(
self
):
request
=
HttpRequest
()
request
.
session
=
self
.
client
.
session
user
=
get_user
(
request
)
self
.
assertIsInstance
(
user
,
AnonymousUser
)
def
test_get_user
(
self
):
created_user
=
User
.
objects
.
create_user
(
'testuser'
,
'test@example.com'
,
'testpw'
)
self
.
client
.
login
(
username
=
'testuser'
,
password
=
'testpw'
)
request
=
HttpRequest
()
request
.
session
=
self
.
client
.
session
user
=
get_user
(
request
)
self
.
assertIsInstance
(
user
,
User
)
self
.
assertEqual
(
user
.
username
,
created_user
.
username
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment