나는 ModelBackend을 조사 중입니다.Django ModelBackend.authenticate는 어떻게 작동합니까?
def authenticate(self, username=None, password=None, **kwargs):
UserModel = get_user_model()
if username is None:
username = kwargs.get(UserModel.USERNAME_FIELD)
try:
user = UserModel._default_manager.get_by_natural_key(username)
except UserModel.DoesNotExist:
# Run the default password hasher once to reduce the timing
# difference between an existing and a non-existing user (#20760).
UserModel().set_password(password)
else:
if user.check_password(password) and self.user_can_authenticate(user):
return user
혼란 스럽습니다.
- 여기는
authenticate()
입니다. authenticate()
-username
및password
을 어떻게 통과?
때로는 코드가 작동하지만, 나는 그것이 어떻게 작동하는지 모르겠어요.
내가 하나 개의 프로젝트의 소스 코드를 읽고있다
UPDATE. authenticate()
의 정의를 찾았지만 어디에서 호출되는지 찾을 수 없습니다.
grep -r "authenticate" .
./src/myproject/views.py: if request.user.is_authenticated():
./src/lib/backend.py: def authenticate(self, username = None, password = None, **kwargs):
./src/lib/middleware.py: if not request.user.is_authenticated():
./src/lib/decorators.py: if request.user.is_authenticated():
어, 당신은 전화, 당신은 그것에게 사용자 이름과 암호를 전달합니다. –
@DanielRoseman 한 프로젝트의 소스 코드를 읽었습니다. 나는 authenticate()의 정의를 찾았지만 어디에서 호출되었는지 찾을 수 없습니다. – BAE
그것은 당신에 의해 호출됩니다. –