def clean_username(self):
        username = self.cleaned_data["username"]
        if '@' in username:
            # The user entered an email, so try to log them in by e-mail
            emails = ContactValue.objects.filter(value=username,
                                                 field__field_type='email',
                                                 contact__trash=False,
                                                 contact__related_user__isnull=False)
            users = [email.contact.related_user.user for email in emails]
        else:
            users = User.objects.filter(user__username=username)
        if len(users) == 0:
            raise forms.ValidationError(
                _("Sorry, we don't know that user or e-mail."))
        else:
            username = users[0]
        return username
Validates that a user exists with the given e-mail address.
dataset/ETHPy150Open treeio/treeio/treeio/core/forms.py/PasswordResetForm.clean_username