Skip to content

Commit e9b27aa

Browse files
committed
fix(account): login placeholder to include phone
1 parent 4f762dd commit e9b27aa

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

allauth/account/forms.py

+26-8
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,11 @@ def __init__(self, *args, **kwargs):
123123
elif app_settings.LOGIN_METHODS == {LoginMethod.PHONE}:
124124
login_field = adapter.phone_form_field(required=True)
125125
else:
126-
assert app_settings.LOGIN_METHODS.issubset(
127-
{
128-
LoginMethod.USERNAME,
129-
LoginMethod.EMAIL,
130-
LoginMethod.PHONE,
131-
}
132-
) # nosec
133126
login_widget = forms.TextInput(
134-
attrs={"placeholder": _("Username or email"), "autocomplete": "email"}
127+
attrs={
128+
"placeholder": self._get_login_field_placeholder(),
129+
"autocomplete": "email",
130+
}
135131
)
136132
login_field = forms.CharField(
137133
label=pgettext("field label", "Login"), widget=login_widget
@@ -142,6 +138,28 @@ def __init__(self, *args, **kwargs):
142138
del self.fields["remember"]
143139
self._setup_password_field()
144140

141+
def _get_login_field_placeholder(self):
142+
methods = app_settings.LOGIN_METHODS
143+
assert len(methods) > 1 # nosec
144+
assert methods.issubset(
145+
{
146+
LoginMethod.USERNAME,
147+
LoginMethod.EMAIL,
148+
LoginMethod.PHONE,
149+
}
150+
) # nosec
151+
if len(methods) == 3:
152+
placeholder = _("Username, email or phone")
153+
elif methods == {LoginMethod.USERNAME, LoginMethod.EMAIL}:
154+
placeholder = _("Username or email")
155+
elif methods == {LoginMethod.USERNAME, LoginMethod.PHONE}:
156+
placeholder = _("Username or phone")
157+
elif methods == {LoginMethod.EMAIL, LoginMethod.PHONE}:
158+
placeholder = _("Email or phone")
159+
else:
160+
raise ValueError(methods)
161+
return placeholder
162+
145163
def _setup_password_field(self):
146164
password_field = app_settings.SIGNUP_FIELDS.get("password1")
147165
if not password_field:

0 commit comments

Comments
 (0)