Skip to content
Open
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
8 changes: 7 additions & 1 deletion openedx/core/djangoapps/user_authn/views/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def _log_and_raise_inactive_user_auth_error(unauthenticated_user):
context={
"platformName": configuration_helpers.get_value("PLATFORM_NAME", settings.PLATFORM_NAME),
"supportLink": configuration_helpers.get_value("SUPPORT_SITE_LINK", settings.SUPPORT_SITE_LINK),
"email": unauthenticated_user.email,
},
)

Expand Down Expand Up @@ -683,7 +684,12 @@ def login_user(request, api_version="v1"): # pylint: disable=too-many-statement
set_custom_attribute("login_error_code", error_code)
email_or_username_key = "email" if api_version == API_V1 else "email_or_username"
email_or_username = request.POST.get(email_or_username_key, None)
email_or_username = possibly_authenticated_user.email if possibly_authenticated_user else email_or_username
if possibly_authenticated_user:
email_or_username = possibly_authenticated_user.email
elif response_content.get("error_code") == "inactive-user" and user is not None:
email_or_username = user.email
elif response_content.get("context", {}).get("email"):
email_or_username = response_content["context"]["email"]
response_content["email"] = email_or_username
except VulnerablePasswordError as error:
response_content = error.get_response()
Expand Down
12 changes: 12 additions & 0 deletions openedx/core/djangoapps/user_authn/views/tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,18 @@ def test_login_not_activated_with_correct_credentials(self):
self._assert_response(response, success=False, error_code="inactive-user")
self._assert_audit_log(mock_audit_log, 'warning', ['Login failed', 'Account not active for user'])

def test_login_not_activated_includes_user_email(self):
self.user.is_active = False
self.user.save()

response, _ = self._login_response(
self.user_email,
self.password,
)
response_dict = json.loads(response.content.decode('utf-8'))
assert response_dict['error_code'] == 'inactive-user'
assert response_dict['email'] == self.user_email

@patch('openedx.core.djangoapps.user_authn.views.login._log_and_raise_inactive_user_auth_error')
def test_login_inactivated_user_with_incorrect_credentials(self, mock_inactive_user_email_and_error):
"""
Expand Down