Skip to content

Backends

hypha.apply.users.backends

UserModel module-attribute

UserModel = get_user_model()

CustomModelBackend

Bases: ModelBackend

authenticate

authenticate(request, username=None, password=None, **kwargs)
Source code in hypha/apply/users/backends.py
def authenticate(self, request, username=None, password=None, **kwargs):
    if username is None:
        username = kwargs.get(UserModel.USERNAME_FIELD)
    if username is None or password is None:
        return

    user = get_user_by_email(username)
    if not user:
        # Run the default password hasher once to reduce the timing
        # difference between an existing and a nonexistent user (#20760).
        UserModel().set_password(password)
    else:
        if user.check_password(password) and self.user_can_authenticate(user):
            return user