From 7b299977b7148bf6042d350f599f8f655b61e22b Mon Sep 17 00:00:00 2001 From: mubbsharanwar Date: Fri, 11 Jun 2021 17:10:02 +0500 Subject: [PATCH] fix:Login failed email_or_username Fix email_or_username null in login failed case. Fixes: VAN-532 --- openedx/core/djangoapps/user_authn/views/login.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/user_authn/views/login.py b/openedx/core/djangoapps/user_authn/views/login.py index 631c83f82e..83944f5b13 100644 --- a/openedx/core/djangoapps/user_authn/views/login.py +++ b/openedx/core/djangoapps/user_authn/views/login.py @@ -499,6 +499,7 @@ def login_user(request, api_version='v1'): return HttpResponseForbidden( "Third party authentication is required to login. Username and password were received instead." ) + possibly_authenticated_user = None try: if third_party_auth_requested and not first_party_auth_requested: # The user has already authenticated via third-party auth and has not @@ -576,8 +577,11 @@ def login_user(request, api_version='v1'): error_code = response_content.get('error_code') if error_code: set_custom_attribute('login_error_code', error_code) - - response_content['email'] = request.POST.get('email', None) + 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 + response_content['email'] = email_or_username response = JsonResponse(response_content, status=400) set_custom_attribute('login_user_auth_failed_error', True) set_custom_attribute('login_user_response_status', response.status_code)