feat: add user details to registration response (#33078)

This commit is contained in:
Zainab Amir
2023-08-23 11:45:43 +05:00
committed by GitHub
parent a4b11c02e0
commit 45fd0b57cf
2 changed files with 10 additions and 1 deletions

View File

@@ -591,7 +591,10 @@ class RegistrationView(APIView):
redirect_to, root_url = get_next_url_for_login_page(request, include_host=True)
redirect_url = get_redirect_url_with_host(root_url, redirect_to)
response = self._create_response(request, {}, status_code=200, redirect_url=redirect_url)
authenticated_user = {'username': user.username, 'user_id': user.id}
response = self._create_response(
request, {'authenticated_user': authenticated_user}, status_code=200, redirect_url=redirect_url
)
set_logged_in_cookies(request, response, user)
if not user.is_active and settings.SHOW_ACCOUNT_ACTIVATION_CTA and not settings.MARKETING_EMAILS_OPT_IN:
response.set_cookie(

View File

@@ -2238,6 +2238,12 @@ class RegistrationViewTestV2(RegistrationViewTestV1):
HTTP_ACCEPT='*/*',
)
self._assert_redirect_url(response, expected_redirect)
assert response.status_code == 200
# Check that authenticated user details are also returned in
# the response for successful registration
decoded_response = json.loads(response.content.decode('utf-8'))
assert decoded_response['authenticated_user'] == {'username': self.USERNAME, 'user_id': 1}
@mock.patch('openedx.core.djangoapps.user_authn.views.register._record_is_marketable_attribute')
def test_logs_for_error_when_setting_is_marketable_attribute(self, set_is_marketable_attr):