<commit_before>from django.contrib.auth import get_user_model
from django import forms
from django.utils.translation import ugettext_lazy as _
from django_cradmin.apps.cradmin_authenticate.views.login import LoginView, UsernameLoginForm


class CustomUsernameLoginForm(UsernameLoginForm):
    username_field = 'shortname'
    shortname = forms.CharField(
        label=_('Username'))
<commit_msg>devilry_authenticate: LDAP fixes<commit_after>from django.contrib.auth import get_user_model
from django import forms
from django.utils.translation import ugettext_lazy as _
from django_cradmin.apps.cradmin_authenticate.views.login import LoginView, UsernameLoginForm


class CustomUsernameLoginForm(UsernameLoginForm):
    username_field = 'shortname'
    shortname = forms.CharField(
        label=_('Username'))

    def clean(self):
        """
        validate the form, and execute :func:`django.contrib.auth.authenticate` to login the user if form is valid.
        """
        username = self.cleaned_data.get(self.username_field)
        password = self.cleaned_data.get('password')
        if username and password:
            authenticated_user = self.authenticate(**{
                'username': username,
                'password': password
            })

            if authenticated_user is None:
                raise forms.ValidationError(self.error_message_invalid_login)
            elif not authenticated_user.is_active:
                raise forms.ValidationError(self.error_message_inactive)
            self.__authenticated_user = authenticated_user
        return self.cleaned_data

{'fraction_non_alphanumeric': 0.07227414330218068, 'fraction_numerical': 0.0, 'mean_word_length': 3.364130434782609, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6328641', 'n_tokens_mistral': 436, 'n_tokens_neox': 421, 'n_words': 97}