diff --git a/common/djangoapps/student/tests/test_activate_account.py b/common/djangoapps/student/tests/test_activate_account.py index 2605dafc6b..31bba1157a 100644 --- a/common/djangoapps/student/tests/test_activate_account.py +++ b/common/djangoapps/student/tests/test_activate_account.py @@ -166,6 +166,22 @@ class TestActivateAccount(TestCase): self.assertRedirects(response, login_page_url) self.assertContains(response, 'Your account could not be activated') + @override_settings(MARKETING_EMAILS_OPT_IN=True) + def test_email_confirmation_notification_on_logistration(self): + """ + Verify that logistration page displays success/error/info messages + about email confirmation instead of activation when MARKETING_EMAILS_OPT_IN + is set to True. + """ + response = self.client.get(reverse('activate', args=[self.registration.activation_key]), follow=True) + self.assertContains(response, 'Success! You have confirmed your email.') + + response = self.client.get(reverse('activate', args=[self.registration.activation_key]), follow=True) + self.assertContains(response, 'This email has already been confirmed.') + + response = self.client.get(reverse('activate', args=[uuid4().hex]), follow=True) + self.assertContains(response, 'Your email could not be confirmed') + @override_settings(LOGIN_REDIRECT_WHITELIST=['localhost:1991']) @override_settings(FEATURES={**FEATURES_WITH_AUTHN_MFE_ENABLED, 'ENABLE_ENTERPRISE_INTEGRATION': True}) @override_waffle_flag(REDIRECT_TO_AUTHN_MICROFRONTEND, active=True) diff --git a/common/djangoapps/student/views/management.py b/common/djangoapps/student/views/management.py index 9c1768a2f3..4f28f7e289 100644 --- a/common/djangoapps/student/views/management.py +++ b/common/djangoapps/student/views/management.py @@ -516,10 +516,15 @@ def activate_account(request, key): monitoring_utils.set_custom_attribute('student_activate_account', 'lms') activation_message_type = None + activated_or_confirmed = 'confirmed' if settings.MARKETING_EMAILS_OPT_IN else 'activated' + account_or_email = 'email' if settings.MARKETING_EMAILS_OPT_IN else 'account' + invalid_message = HTML(_( - '{html_start}Your account could not be activated{html_end}' + '{html_start}Your {account_or_email} could not be {activated_or_confirmed}{html_end}' 'Something went wrong, please contact support to resolve this issue.' )).format( + account_or_email=account_or_email, + activated_or_confirmed=activated_or_confirmed, support_url=configuration_helpers.get_value( 'ACTIVATION_EMAIL_SUPPORT_LINK', settings.ACTIVATION_EMAIL_SUPPORT_LINK ) or settings.SUPPORT_SITE_LINK, @@ -549,7 +554,11 @@ def activate_account(request, key): activation_message_type = 'info' messages.info( request, - HTML(_('{html_start}This account has already been activated.{html_end}')).format( + HTML(_( + '{html_start}This {account_or_email} has already been {activated_or_confirmed}.{html_end}' + )).format( + account_or_email=account_or_email, + activated_or_confirmed=activated_or_confirmed, html_start=HTML('

'), html_end=HTML('

'), ), @@ -558,7 +567,7 @@ def activate_account(request, key): else: registration.activate() # Success message for logged in users. - message = _('{html_start}Success{html_end} You have activated your account.') + message = _('{html_start}Success{html_end} You have {activated_or_confirmed} your {account_or_email}.') tracker.emit( USER_ACCOUNT_ACTIVATED, @@ -571,7 +580,7 @@ def activate_account(request, key): if not request.user.is_authenticated: # Success message for logged out users message = _( - '{html_start}Success! You have activated your account.{html_end}' + '{html_start}Success! You have {activated_or_confirmed} your {account_or_email}.{html_end}' 'You will now receive email updates and alerts from us related to' ' the courses you are enrolled in. Sign In to continue.' ) @@ -581,6 +590,8 @@ def activate_account(request, key): messages.success( request, HTML(message).format( + account_or_email=account_or_email, + activated_or_confirmed=activated_or_confirmed, html_start=HTML('

'), html_end=HTML('

'), ),