diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2019-03-10 11:03:42 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton@noumenal.es> | 2019-06-07 12:44:39 +0200 |
| commit | dcb8f00d06eec99072b78d54215c9a3dc04acb99 (patch) | |
| tree | c5f55c29e3d55df56644ed6738809f1d0330e5e2 /django | |
| parent | c498f088c584ec3aff97409fdc11b39b28240de9 (diff) | |
Fixed #29379 -- Added autocomplete attribute to contrib.auth.forms fields.
Thank you to Nick Pope for review.
Co-authored-by: CHI Cheng <cloudream@gmail.com>
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/auth/forms.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index ca7529ab5f..23d5bdafed 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -78,12 +78,12 @@ class UserCreationForm(forms.ModelForm): password1 = forms.CharField( label=_("Password"), strip=False, - widget=forms.PasswordInput, + widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}), help_text=password_validation.password_validators_help_text_html(), ) password2 = forms.CharField( label=_("Password confirmation"), - widget=forms.PasswordInput, + widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}), strip=False, help_text=_("Enter the same password as before, for verification."), ) @@ -96,7 +96,10 @@ class UserCreationForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if self._meta.model.USERNAME_FIELD in self.fields: - self.fields[self._meta.model.USERNAME_FIELD].widget.attrs.update({'autofocus': True}) + self.fields[self._meta.model.USERNAME_FIELD].widget.attrs.update({ + 'autocomplete': 'username', + 'autofocus': True, + }) def clean_password2(self): password1 = self.cleaned_data.get("password1") @@ -163,11 +166,11 @@ class AuthenticationForm(forms.Form): Base class for authenticating users. Extend this to get a form that accepts username/password logins. """ - username = UsernameField(widget=forms.TextInput(attrs={'autofocus': True})) + username = UsernameField(widget=forms.TextInput(attrs={'autocomplete': 'username', 'autofocus': True})) password = forms.CharField( label=_("Password"), strip=False, - widget=forms.PasswordInput, + widget=forms.PasswordInput(attrs={'autocomplete': 'current-password'}), ) error_messages = { @@ -235,7 +238,11 @@ class AuthenticationForm(forms.Form): class PasswordResetForm(forms.Form): - email = forms.EmailField(label=_("Email"), max_length=254) + email = forms.EmailField( + label=_("Email"), + max_length=254, + widget=forms.EmailInput(attrs={'autocomplete': 'email'}) + ) def send_mail(self, subject_template_name, email_template_name, context, from_email, to_email, html_email_template_name=None): @@ -311,14 +318,14 @@ class SetPasswordForm(forms.Form): } new_password1 = forms.CharField( label=_("New password"), - widget=forms.PasswordInput, + widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}), strip=False, help_text=password_validation.password_validators_help_text_html(), ) new_password2 = forms.CharField( label=_("New password confirmation"), strip=False, - widget=forms.PasswordInput, + widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}), ) def __init__(self, user, *args, **kwargs): @@ -357,7 +364,7 @@ class PasswordChangeForm(SetPasswordForm): old_password = forms.CharField( label=_("Old password"), strip=False, - widget=forms.PasswordInput(attrs={'autofocus': True}), + widget=forms.PasswordInput(attrs={'autocomplete': 'current-password', 'autofocus': True}), ) field_order = ['old_password', 'new_password1', 'new_password2'] @@ -385,13 +392,13 @@ class AdminPasswordChangeForm(forms.Form): required_css_class = 'required' password1 = forms.CharField( label=_("Password"), - widget=forms.PasswordInput(attrs={'autofocus': True}), + widget=forms.PasswordInput(attrs={'autocomplete': 'new-password', 'autofocus': True}), strip=False, help_text=password_validation.password_validators_help_text_html(), ) password2 = forms.CharField( label=_("Password (again)"), - widget=forms.PasswordInput, + widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}), strip=False, help_text=_("Enter the same password as before, for verification."), ) |
