Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(accounts): add autocomplete hints for password field #11697

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Not yet released.
**Improvements**

* :ref:`subscriptions` now include strings which need updating.
* Improved compatibility with password managers.

**Bug fixes**

Expand Down
17 changes: 13 additions & 4 deletions weblate/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@ def clean_email(self):
class PasswordField(forms.CharField):
"""Password field."""

def __init__(self, *args, **kwargs) -> None:
kwargs["widget"] = forms.PasswordInput(render_value=False)
def __init__(self, new_password: bool = False, **kwargs) -> None:
kwargs["widget"] = forms.PasswordInput(
attrs={
"autocomplete": "new-password" if new_password else "current-password"
},
render_value=False,
)
kwargs["max_length"] = 256
kwargs["strip"] = False
super().__init__(*args, **kwargs)
super().__init__(**kwargs)


class UniqueUsernameField(UsernameField):
Expand Down Expand Up @@ -465,8 +470,12 @@ class SetPasswordForm(DjangoSetPasswordForm):
new_password1 = PasswordField(
label=gettext_lazy("New password"),
help_text=password_validation.password_validators_help_text_html(),
new_password=True,
)
new_password2 = PasswordField(
label=gettext_lazy("New password confirmation"),
new_password=True,
)
new_password2 = PasswordField(label=gettext_lazy("New password confirmation"))

@transaction.atomic
def save(self, request, delete_session=False) -> None:
Expand Down
Loading