Skip to content

Commit

Permalink
Warn users that logging in with email addresses is not supported
Browse files Browse the repository at this point in the history
Fixes: #1475

Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed Jan 17, 2025
1 parent ced56da commit 65747c7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/1475.bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warn users that logging in with email addresses is not supported
3 changes: 2 additions & 1 deletion noggin/form/login_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from wtforms.validators import DataRequired, Optional

from .base import ModestForm, SubmitButtonField
from .validators import no_mixed_case
from .validators import no_email, no_mixed_case


class LoginUserForm(ModestForm):
username = StringField(
_('Username'),
validators=[
DataRequired(message=_('You must provide a user name')),
no_email,
no_mixed_case,
],
)
Expand Down
5 changes: 5 additions & 0 deletions noggin/form/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ def __call__(self, form, field):
for pattern in patterns:
if re.match(pattern, value):
raise ValidationError(self.message % {"pattern": pattern})


def no_email(form, field):
if "@" in field.data:
raise ValidationError(_("Please use your username, not your email address."))
17 changes: 17 additions & 0 deletions tests/unit/controller/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,23 @@ def test_login_bad_format(client, mocker, username):
assert maybe_ipa_login.call_args_list[0][0][2] == username


def test_login_email_address(client):
"""Test giving an email address instead of a username"""
result = client.post(
'/',
data={
"login-username": "[email protected]",
"login-password": "dummy_password",
"login-submit": "1",
},
)
assert_form_field_error(
result,
"login-username",
"Please use your username, not your email address.",
)


@pytest.mark.vcr()
def test_login_incorrect_password(client, dummy_user):
"""Test a incorrect password"""
Expand Down

0 comments on commit 65747c7

Please sign in to comment.