prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  User creation in the admin is broken
  Sentry Issue: [CONCREXIT-3F](https://sentry.io/organizations/thalia/issues/1844597243/?referrer=github_integration)
  
  ```
  FieldError: Unknown field(s) (password2, password1) specified for User
    File "django/contrib/admin/options.py", line 702, in get_form
      return modelform_factory(self.model, **defaults)
    File "django/forms/models.py", line 554, in modelform_factory
      return type(form)(class_name, (form,), form_class_attrs)
    File "django/forms/models.py", line 267, in __new__
      raise FieldError(message)
  
  FieldError: Unknown field(s) (password2, password1) specified for User. Check fields/fieldsets/exclude attributes of class UserAdmin.
  (15 additional frame(s) were not displayed)
  ...
    File "django/utils/decorators.py", line 130, in _wrapped_view
      response = view_func(request, *args, **kwargs)
    File "django/contrib/admin/options.py", line 1522, in changeform_view
      return self._changeform_view(request, object_id, form_url, extra_context)
    File "django/contrib/admin/options.py", line 1555, in _changeform_view
      ModelForm = self.get_form(request, obj, change=not add)
    File "django/contrib/auth/admin.py", line 80, in get_form
      return super().get_form(request, obj, **defaults)
    File "django/contrib/admin/options.py", line 704, in get_form
      raise FieldError(
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `website/members/forms.py`
  Content:
  ```
  1 """Forms defined by the members package."""
  2 from django import forms
  3 from django.conf import settings
  4 from django.contrib.auth import get_user_model
  5 from django.contrib.auth.forms import UserChangeForm as BaseUserChangeForm
  6 from django.contrib.auth.forms import UserCreationForm as BaseUserCreationForm
  7 from django.core.validators import RegexValidator
  8 from django.utils.translation import gettext_lazy as _
  9 
  10 from members import emails
  11 from .models import Profile
  12 
  13 
  14 class ProfileForm(forms.ModelForm):
  15     """Form with all the user editable fields of a Profile model."""
  16 
  17     class Meta:
  18         fields = [
  19             "show_birthday",
  20             "address_street",
  21             "address_street2",
  22             "address_postal_code",
  23             "address_city",
  24             "address_country",
  25             "phone_number",
  26             "emergency_contact",
  27             "emergency_contact_phone_number",
  28             "website",
  29             "profile_description",
  30             "nickname",
  31             "initials",
  32             "display_name_preference",
  33             "photo",
  34             "receive_optin",
  35             "receive_newsletter",
  36             "receive_magazine",
  37             "email_gsuite_only",
  38         ]
  39         model = Profile
  40 
  41     def __init__(self, *args, **kwargs):
  42         super().__init__(*args, **kwargs)
  43         if not kwargs["instance"].user.is_staff:
  44             self.fields["email_gsuite_only"].widget = self.fields[
  45                 "email_gsuite_only"
  46             ].hidden_widget()
  47 
  48 
  49 class UserCreationForm(BaseUserCreationForm):
  50     """Custom Form that removes the password fields from user creation and sends a welcome message when a user is created."""
  51 
  52     # Don't forget to edit the formset in admin.py!
  53     # This is a stupid quirk of the user admin.
  54 
  55     # shadow the password fields to prevent validation errors,
  56     #   since we generate the passwords dynamically.
  57     password1 = None
  58     password2 = None
  59 
  60     def __init__(self, *args, **kwargs):
  61         super().__init__(*args, **kwargs)
  62         for field in ("email", "first_name", "last_name"):
  63             self.fields[field].required = True
  64 
  65     send_welcome_email = forms.BooleanField(
  66         label=_("Send welcome email"),
  67         help_text=_("This email will include the generated password"),
  68         required=False,
  69         initial=True,
  70     )
  71 
  72     def clean(self):
  73         if "username" in self.cleaned_data:
  74             self.cleaned_data["username"] = self.cleaned_data["username"].lower()
  75         super().clean()
  76 
  77     def save(self, commit=True):
  78         password = get_user_model().objects.make_random_password(length=15)
  79         # pass the password on as if it was filled in, so that save() works
  80         self.cleaned_data["password1"] = password
  81         user = super().save(commit=False)
  82         user.set_password(password)
  83         if commit:
  84             user.save()
  85         if self.cleaned_data["send_welcome_email"]:
  86             language = settings.LANGUAGE_CODE
  87             emails.send_welcome_message(user, password, language)
  88         return user
  89 
  90     class Meta:
  91         fields = ("username", "first_name", "last_name", "send_welcome_email")
  92 
  93 
  94 class UserChangeForm(BaseUserChangeForm):
  95     """Custom user edit form that adds fields for first/last name and email.
  96 
  97     It also force-lowercases the username on save
  98     """
  99 
  100     username = forms.CharField(
  101         label=_("Username"),
  102         required=True,
  103         help_text=_("Required. 64 characters or fewer. Letters and digits only."),
  104         widget=forms.TextInput(attrs={"class": "vTextField", "maxlength": 64}),
  105         validators=[
  106             RegexValidator(
  107                 regex="^[a-zA-Z0-9]{1,64}$",
  108                 message=_(
  109                     "Please use 64 characters or fewer. Letters and digits only."
  110                 ),
  111             )
  112         ],
  113     )
  114 
  115     first_name = forms.CharField(
  116         label=_("First name"),
  117         required=True,
  118         widget=forms.TextInput(attrs={"class": "vTextField", "maxlength": 30}),
  119     )
  120     last_name = forms.CharField(
  121         label=_("Last name"),
  122         required=True,
  123         widget=forms.TextInput(attrs={"class": "vTextField", "maxlength": 150}),
  124     )
  125     email = forms.CharField(
  126         label=_("Email address"),
  127         required=True,
  128         widget=forms.EmailInput(attrs={"class": "vTextField", "maxlength": 254}),
  129     )
  130 
  131     def clean(self):
  132         if "username" in self.cleaned_data:
  133             self.cleaned_data["username"] = self.cleaned_data["username"].lower()
  134         super().clean()
  135
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/website/members/forms.py b/website/members/forms.py
  --- a/website/members/forms.py
  +++ b/website/members/forms.py
  @@ -1,13 +1,10 @@
   """Forms defined by the members package."""
   from django import forms
  -from django.conf import settings
  -from django.contrib.auth import get_user_model
   from django.contrib.auth.forms import UserChangeForm as BaseUserChangeForm
   from django.contrib.auth.forms import UserCreationForm as BaseUserCreationForm
   from django.core.validators import RegexValidator
   from django.utils.translation import gettext_lazy as _
   
  -from members import emails
   from .models import Profile
   
   
  @@ -47,48 +44,15 @@
   
   
   class UserCreationForm(BaseUserCreationForm):
  -    """Custom Form that removes the password fields from user creation and sends a welcome message when a user is created."""
  -
  -    # Don't forget to edit the formset in admin.py!
  -    # This is a stupid quirk of the user admin.
  -
  -    # shadow the password fields to prevent validation errors,
  -    #   since we generate the passwords dynamically.
  -    password1 = None
  -    password2 = None
  -
  -    def __init__(self, *args, **kwargs):
  -        super().__init__(*args, **kwargs)
  -        for field in ("email", "first_name", "last_name"):
  -            self.fields[field].required = True
  -
  -    send_welcome_email = forms.BooleanField(
  -        label=_("Send welcome email"),
  -        help_text=_("This email will include the generated password"),
  -        required=False,
  -        initial=True,
  -    )
  +    """Custom Form that lowercases the username on creation."""
   
       def clean(self):
           if "username" in self.cleaned_data:
               self.cleaned_data["username"] = self.cleaned_data["username"].lower()
           super().clean()
   
  -    def save(self, commit=True):
  -        password = get_user_model().objects.make_random_password(length=15)
  -        # pass the password on as if it was filled in, so that save() works
  -        self.cleaned_data["password1"] = password
  -        user = super().save(commit=False)
  -        user.set_password(password)
  -        if commit:
  -            user.save()
  -        if self.cleaned_data["send_welcome_email"]:
  -            language = settings.LANGUAGE_CODE
  -            emails.send_welcome_message(user, password, language)
  -        return user
  -
       class Meta:
  -        fields = ("username", "first_name", "last_name", "send_welcome_email")
  +        fields = ("username", "first_name", "last_name")
   
   
   class UserChangeForm(BaseUserChangeForm):
  
verification_info: {"golden_diff": "diff --git a/website/members/forms.py b/website/members/forms.py\n--- a/website/members/forms.py\n+++ b/website/members/forms.py\n@@ -1,13 +1,10 @@\n \"\"\"Forms defined by the members package.\"\"\"\n from django import forms\n-from django.conf import settings\n-from django.contrib.auth import get_user_model\n from django.contrib.auth.forms import UserChangeForm as BaseUserChangeForm\n from django.contrib.auth.forms import UserCreationForm as BaseUserCreationForm\n from django.core.validators import RegexValidator\n from django.utils.translation import gettext_lazy as _\n \n-from members import emails\n from .models import Profile\n \n \n@@ -47,48 +44,15 @@\n \n \n class UserCreationForm(BaseUserCreationForm):\n-    \"\"\"Custom Form that removes the password fields from user creation and sends a welcome message when a user is created.\"\"\"\n-\n-    # Don't forget to edit the formset in admin.py!\n-    # This is a stupid quirk of the user admin.\n-\n-    # shadow the password fields to prevent validation errors,\n-    #   since we generate the passwords dynamically.\n-    password1 = None\n-    password2 = None\n-\n-    def __init__(self, *args, **kwargs):\n-        super().__init__(*args, **kwargs)\n-        for field in (\"email\", \"first_name\", \"last_name\"):\n-            self.fields[field].required = True\n-\n-    send_welcome_email = forms.BooleanField(\n-        label=_(\"Send welcome email\"),\n-        help_text=_(\"This email will include the generated password\"),\n-        required=False,\n-        initial=True,\n-    )\n+    \"\"\"Custom Form that lowercases the username on creation.\"\"\"\n \n     def clean(self):\n         if \"username\" in self.cleaned_data:\n             self.cleaned_data[\"username\"] = self.cleaned_data[\"username\"].lower()\n         super().clean()\n \n-    def save(self, commit=True):\n-        password = get_user_model().objects.make_random_password(length=15)\n-        # pass the password on as if it was filled in, so that save() works\n-        self.cleaned_data[\"password1\"] = password\n-        user = super().save(commit=False)\n-        user.set_password(password)\n-        if commit:\n-            user.save()\n-        if self.cleaned_data[\"send_welcome_email\"]:\n-            language = settings.LANGUAGE_CODE\n-            emails.send_welcome_message(user, password, language)\n-        return user\n-\n     class Meta:\n-        fields = (\"username\", \"first_name\", \"last_name\", \"send_welcome_email\")\n+        fields = (\"username\", \"first_name\", \"last_name\")\n \n \n class UserChangeForm(BaseUserChangeForm):\n", "issue": "User creation in the admin is broken\nSentry Issue: [CONCREXIT-3F](https://sentry.io/organizations/thalia/issues/1844597243/?referrer=github_integration)\n\n```\nFieldError: Unknown field(s) (password2, password1) specified for User\n  File \"django/contrib/admin/options.py\", line 702, in get_form\n    return modelform_factory(self.model, **defaults)\n  File \"django/forms/models.py\", line 554, in modelform_factory\n    return type(form)(class_name, (form,), form_class_attrs)\n  File \"django/forms/models.py\", line 267, in __new__\n    raise FieldError(message)\n\nFieldError: Unknown field(s) (password2, password1) specified for User. Check fields/fieldsets/exclude attributes of class UserAdmin.\n(15 additional frame(s) were not displayed)\n...\n  File \"django/utils/decorators.py\", line 130, in _wrapped_view\n    response = view_func(request, *args, **kwargs)\n  File \"django/contrib/admin/options.py\", line 1522, in changeform_view\n    return self._changeform_view(request, object_id, form_url, extra_context)\n  File \"django/contrib/admin/options.py\", line 1555, in _changeform_view\n    ModelForm = self.get_form(request, obj, change=not add)\n  File \"django/contrib/auth/admin.py\", line 80, in get_form\n    return super().get_form(request, obj, **defaults)\n  File \"django/contrib/admin/options.py\", line 704, in get_form\n    raise FieldError(\n```\n", "before_files": [{"content": "\"\"\"Forms defined by the members package.\"\"\"\nfrom django import forms\nfrom django.conf import settings\nfrom django.contrib.auth import get_user_model\nfrom django.contrib.auth.forms import UserChangeForm as BaseUserChangeForm\nfrom django.contrib.auth.forms import UserCreationForm as BaseUserCreationForm\nfrom django.core.validators import RegexValidator\nfrom django.utils.translation import gettext_lazy as _\n\nfrom members import emails\nfrom .models import Profile\n\n\nclass ProfileForm(forms.ModelForm):\n    \"\"\"Form with all the user editable fields of a Profile model.\"\"\"\n\n    class Meta:\n        fields = [\n            \"show_birthday\",\n            \"address_street\",\n            \"address_street2\",\n            \"address_postal_code\",\n            \"address_city\",\n            \"address_country\",\n            \"phone_number\",\n            \"emergency_contact\",\n            \"emergency_contact_phone_number\",\n            \"website\",\n            \"profile_description\",\n            \"nickname\",\n            \"initials\",\n            \"display_name_preference\",\n            \"photo\",\n            \"receive_optin\",\n            \"receive_newsletter\",\n            \"receive_magazine\",\n            \"email_gsuite_only\",\n        ]\n        model = Profile\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        if not kwargs[\"instance\"].user.is_staff:\n            self.fields[\"email_gsuite_only\"].widget = self.fields[\n                \"email_gsuite_only\"\n            ].hidden_widget()\n\n\nclass UserCreationForm(BaseUserCreationForm):\n    \"\"\"Custom Form that removes the password fields from user creation and sends a welcome message when a user is created.\"\"\"\n\n    # Don't forget to edit the formset in admin.py!\n    # This is a stupid quirk of the user admin.\n\n    # shadow the password fields to prevent validation errors,\n    #   since we generate the passwords dynamically.\n    password1 = None\n    password2 = None\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        for field in (\"email\", \"first_name\", \"last_name\"):\n            self.fields[field].required = True\n\n    send_welcome_email = forms.BooleanField(\n        label=_(\"Send welcome email\"),\n        help_text=_(\"This email will include the generated password\"),\n        required=False,\n        initial=True,\n    )\n\n    def clean(self):\n        if \"username\" in self.cleaned_data:\n            self.cleaned_data[\"username\"] = self.cleaned_data[\"username\"].lower()\n        super().clean()\n\n    def save(self, commit=True):\n        password = get_user_model().objects.make_random_password(length=15)\n        # pass the password on as if it was filled in, so that save() works\n        self.cleaned_data[\"password1\"] = password\n        user = super().save(commit=False)\n        user.set_password(password)\n        if commit:\n            user.save()\n        if self.cleaned_data[\"send_welcome_email\"]:\n            language = settings.LANGUAGE_CODE\n            emails.send_welcome_message(user, password, language)\n        return user\n\n    class Meta:\n        fields = (\"username\", \"first_name\", \"last_name\", \"send_welcome_email\")\n\n\nclass UserChangeForm(BaseUserChangeForm):\n    \"\"\"Custom user edit form that adds fields for first/last name and email.\n\n    It also force-lowercases the username on save\n    \"\"\"\n\n    username = forms.CharField(\n        label=_(\"Username\"),\n        required=True,\n        help_text=_(\"Required. 64 characters or fewer. Letters and digits only.\"),\n        widget=forms.TextInput(attrs={\"class\": \"vTextField\", \"maxlength\": 64}),\n        validators=[\n            RegexValidator(\n                regex=\"^[a-zA-Z0-9]{1,64}$\",\n                message=_(\n                    \"Please use 64 characters or fewer. Letters and digits only.\"\n                ),\n            )\n        ],\n    )\n\n    first_name = forms.CharField(\n        label=_(\"First name\"),\n        required=True,\n        widget=forms.TextInput(attrs={\"class\": \"vTextField\", \"maxlength\": 30}),\n    )\n    last_name = forms.CharField(\n        label=_(\"Last name\"),\n        required=True,\n        widget=forms.TextInput(attrs={\"class\": \"vTextField\", \"maxlength\": 150}),\n    )\n    email = forms.CharField(\n        label=_(\"Email address\"),\n        required=True,\n        widget=forms.EmailInput(attrs={\"class\": \"vTextField\", \"maxlength\": 254}),\n    )\n\n    def clean(self):\n        if \"username\" in self.cleaned_data:\n            self.cleaned_data[\"username\"] = self.cleaned_data[\"username\"].lower()\n        super().clean()\n", "path": "website/members/forms.py"}], "after_files": [{"content": "\"\"\"Forms defined by the members package.\"\"\"\nfrom django import forms\nfrom django.contrib.auth.forms import UserChangeForm as BaseUserChangeForm\nfrom django.contrib.auth.forms import UserCreationForm as BaseUserCreationForm\nfrom django.core.validators import RegexValidator\nfrom django.utils.translation import gettext_lazy as _\n\nfrom .models import Profile\n\n\nclass ProfileForm(forms.ModelForm):\n    \"\"\"Form with all the user editable fields of a Profile model.\"\"\"\n\n    class Meta:\n        fields = [\n            \"show_birthday\",\n            \"address_street\",\n            \"address_street2\",\n            \"address_postal_code\",\n            \"address_city\",\n            \"address_country\",\n            \"phone_number\",\n            \"emergency_contact\",\n            \"emergency_contact_phone_number\",\n            \"website\",\n            \"profile_description\",\n            \"nickname\",\n            \"initials\",\n            \"display_name_preference\",\n            \"photo\",\n            \"receive_optin\",\n            \"receive_newsletter\",\n            \"receive_magazine\",\n            \"email_gsuite_only\",\n        ]\n        model = Profile\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        if not kwargs[\"instance\"].user.is_staff:\n            self.fields[\"email_gsuite_only\"].widget = self.fields[\n                \"email_gsuite_only\"\n            ].hidden_widget()\n\n\nclass UserCreationForm(BaseUserCreationForm):\n    \"\"\"Custom Form that lowercases the username on creation.\"\"\"\n\n    def clean(self):\n        if \"username\" in self.cleaned_data:\n            self.cleaned_data[\"username\"] = self.cleaned_data[\"username\"].lower()\n        super().clean()\n\n    class Meta:\n        fields = (\"username\", \"first_name\", \"last_name\")\n\n\nclass UserChangeForm(BaseUserChangeForm):\n    \"\"\"Custom user edit form that adds fields for first/last name and email.\n\n    It also force-lowercases the username on save\n    \"\"\"\n\n    username = forms.CharField(\n        label=_(\"Username\"),\n        required=True,\n        help_text=_(\"Required. 64 characters or fewer. Letters and digits only.\"),\n        widget=forms.TextInput(attrs={\"class\": \"vTextField\", \"maxlength\": 64}),\n        validators=[\n            RegexValidator(\n                regex=\"^[a-zA-Z0-9]{1,64}$\",\n                message=_(\n                    \"Please use 64 characters or fewer. Letters and digits only.\"\n                ),\n            )\n        ],\n    )\n\n    first_name = forms.CharField(\n        label=_(\"First name\"),\n        required=True,\n        widget=forms.TextInput(attrs={\"class\": \"vTextField\", \"maxlength\": 30}),\n    )\n    last_name = forms.CharField(\n        label=_(\"Last name\"),\n        required=True,\n        widget=forms.TextInput(attrs={\"class\": \"vTextField\", \"maxlength\": 150}),\n    )\n    email = forms.CharField(\n        label=_(\"Email address\"),\n        required=True,\n        widget=forms.EmailInput(attrs={\"class\": \"vTextField\", \"maxlength\": 254}),\n    )\n\n    def clean(self):\n        if \"username\" in self.cleaned_data:\n            self.cleaned_data[\"username\"] = self.cleaned_data[\"username\"].lower()\n        super().clean()\n", "path": "website/members/forms.py"}]}