From 5097bd6e546e2399405758f4717b3af682afdb1b Mon Sep 17 00:00:00 2001 From: Matt Drayer Date: Tue, 2 May 2017 09:21:59 -0400 Subject: [PATCH] mattdrayer/ENT-328: Update account activation message on sign-in form. --- cms/envs/common.py | 3 ++ common/djangoapps/student/tests/test_login.py | 6 +-- common/djangoapps/student/views.py | 38 +++++++++++++++++-- .../third_party_auth/tests/specs/base.py | 2 +- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index fd69246a41..e9871260a6 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -90,7 +90,10 @@ from lms.envs.common import ( FILE_UPLOAD_STORAGE_PREFIX, COURSE_ENROLLMENT_MODES, + HELP_TOKENS_BOOKS, + + SUPPORT_SITE_LINK, ) from path import Path as path from warnings import simplefilter diff --git a/common/djangoapps/student/tests/test_login.py b/common/djangoapps/student/tests/test_login.py index 3eeaa02de3..cc0e6d766f 100644 --- a/common/djangoapps/student/tests/test_login.py +++ b/common/djangoapps/student/tests/test_login.py @@ -126,7 +126,7 @@ class LoginTest(CacheIsolationTestCase): # Should now be unable to login response, mock_audit_log = self._login_response('test@edx.org', 'test_password') self._assert_response(response, success=False, - value="Before you sign in, you need to activate your account") + value="In order to sign in, you need to activate your account.") self._assert_audit_log(mock_audit_log, 'warning', [u'Login failed', u'Account not active for user']) @patch.dict("django.conf.settings.FEATURES", {'SQUELCH_PII_IN_LOGS': True}) @@ -138,7 +138,7 @@ class LoginTest(CacheIsolationTestCase): # Should now be unable to login response, mock_audit_log = self._login_response('test@edx.org', 'test_password') self._assert_response(response, success=False, - value="Before you sign in, you need to activate your account") + value="In order to sign in, you need to activate your account.") self._assert_audit_log(mock_audit_log, 'warning', [u'Login failed', u'Account not active for user']) self._assert_not_in_audit_log(mock_audit_log, 'warning', [u'test']) @@ -408,7 +408,7 @@ class LoginTest(CacheIsolationTestCase): if value is not None: msg = ("'%s' did not contain '%s'" % - (str(response_dict['value']), str(value))) + (unicode(response_dict['value']), unicode(value))) self.assertIn(value, response_dict['value'], msg) def _assert_audit_log(self, mock_audit_log, level, log_strings): diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 0dd4f3cf52..c943a3b6f8 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -1236,6 +1236,39 @@ def change_enrollment(request, check_access=True): return HttpResponseBadRequest(_("Enrollment action is invalid")) +def _generate_not_activated_message(user): + """ + Generates the message displayed on the sign-in screen when a learner attempts to access the + system with an inactive account. + + Arguments: + user (User): User object for the learner attempting to sign in. + """ + + support_url = configuration_helpers.get_value( + 'SUPPORT_SITE_LINK', + settings.SUPPORT_SITE_LINK + ) + + platform_name = configuration_helpers.get_value( + 'PLATFORM_NAME', + settings.PLATFORM_NAME + ) + + not_activated_msg_template = _('In order to sign in, you need to activate your account.

' + 'We just sent an activation link to {email}. If ' + 'you do not receive an email, check your spam folders or ' + 'contact {platform} Support.') + + not_activated_message = not_activated_msg_template.format( + email=user.email, + support_url=support_url, + platform=platform_name + ) + + return not_activated_message + + # Need different levels of logging @ensure_csrf_cookie def login_user(request, error=""): # pylint: disable=too-many-statements,unused-argument @@ -1456,11 +1489,10 @@ def login_user(request, error=""): # pylint: disable=too-many-statements,unused AUDIT_LOG.warning(u"Login failed - Account not active for user {0}, resending activation".format(username)) reactivation_email_for_user(user) - not_activated_msg = _("Before you sign in, you need to activate your account. We have sent you an " - "email message with instructions for activating your account.") + return JsonResponse({ "success": False, - "value": not_activated_msg, + "value": _generate_not_activated_message(user), }) # TODO: this should be status code 400 # pylint: disable=fixme diff --git a/common/djangoapps/third_party_auth/tests/specs/base.py b/common/djangoapps/third_party_auth/tests/specs/base.py index f879ebf332..36c88b2c7e 100644 --- a/common/djangoapps/third_party_auth/tests/specs/base.py +++ b/common/djangoapps/third_party_auth/tests/specs/base.py @@ -365,7 +365,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase): self.assertEqual(200, response.status_code) # Yes, it's a 200 even though it's a failure. payload = json.loads(response.content) self.assertFalse(payload.get('success')) - self.assertIn('Before you sign in, you need to activate your account', payload.get('value')) + self.assertIn('In order to sign in, you need to activate your account.', payload.get('value')) def assert_json_failure_response_is_missing_social_auth(self, response): """Asserts failure on /login for missing social auth looks right."""