Skip to content

Commit

Permalink
feat(accounts): add autocomplete hints for password field
Browse files Browse the repository at this point in the history
This makes it possible to generate new passwords instead of filling in
existing one.

Thanks to @spaze for hint on this.
  • Loading branch information
nijel committed May 23, 2024
1 parent 2dc037d commit 1b4a796
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
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

0 comments on commit 1b4a796

Please sign in to comment.