<commit_before>from django.contrib.auth.forms import UserCreationForm
from django.utils.translation import ugettext_lazy as _


class KspUserCreationForm(UserCreationForm):
    """
    A custom user creation form that can make the password fields
    optional.
    """
    class Meta(UserCreationForm.Meta):
        fields = ('username', 'first_name', 'last_name', 'email')

    def __init__(self, password_required=True, *args, **kwargs):
        super(KspUserCreationForm, self).__init__(*args, **kwargs)
        self.password_required = password_<PASSWORD>

        if not password_required:
            self.fields['password1'].required = False
            self.fields['password2'].required = False
            self.fields['password1'].help_text = _(
                "Since you're logging in using an external provider, "
                "this field is optional; however, by supplying it, you "
                "will be able to log in using a password."
            )

    def clean_password2(self):
        """
        We need to validate the submitted passwords if they are required
        or either has been submitted, otherwise the user account will be
        passwordless.
        """
        if (self.password_required or self.cleaned_data.get('password1') or
            self.cleaned_data.get('password2')):
            return super(KspUserCreationForm, self).clean_password2()
        return None<commit_msg>ksp_login: users without password no longer have a blank password set<commit_after>from django.contrib.auth.forms import UserCreationForm
from django.utils.translation import ugettext_lazy as _


class KspUserCreationForm(UserCreationForm):
    """
    A custom user creation form that can make the password fields
    optional.
    """
    class Meta(UserCreationForm.Meta):
        fields = ('username', 'first_name', 'last_name', 'email')

    def __init__(self, password_required=True, *args, **kwargs):
        super(KspUserCreationForm, self).__init__(*args, **kwargs)
        self.password_required = password_<PASSWORD>

        if not password_required:
            self.fields['password1'].required = False
            self.fields['password2'].required = False
            self.fields['password1'].help_text = _(
                "Since you're logging in using an external provider, "
                "this field is optional; however, by supplying it, you "
                "will be able to log in using a password."
            )

    def clean_password2(self):
        """
        We need to validate the submitted passwords if they are required
        or either has been submitted, otherwise the user account will be
        passwordless.
        """
        if (self.password_required or self.cleaned_data.get('password1') or
            self.cleaned_data.get('password2')):
            return super(KspUserCreationForm, self).clean_password2()
        return None

    def save(self, commit=True):
        """
        If a password was provided or is required, just delegate to the
        parent's save, otherwise explicitly set an unusable password.
        """
        user = super(KspUserCreationForm, self).save(commit=False)
        if not (self.cleaned_data.get('password1') or
                self.password_required):
            user.set_unusable_password()
        if commit:
            user.save()
        return user
{'fraction_non_alphanumeric': 0.08882947118241236, 'fraction_numerical': 0.004456327985739751, 'mean_word_length': 2.578108395324123, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4182013', 'n_tokens_mistral': 873, 'n_tokens_neox': 848, 'n_words': 266}