From 16ceb8103ca3e8d998dacecc157b7d928faf1131 Mon Sep 17 00:00:00 2001 From: Bessie Steinberg Date: Fri, 22 Feb 2019 13:25:35 -0500 Subject: [PATCH] ENT-1591: Validate Recovery Email a Primary Email - On the accounts page validate that a recovery email is not any of the existing primary emails or one that has been retired. --- common/djangoapps/student/views/management.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/common/djangoapps/student/views/management.py b/common/djangoapps/student/views/management.py index cfe1e84922..4e3bdec55b 100644 --- a/common/djangoapps/student/views/management.py +++ b/common/djangoapps/student/views/management.py @@ -974,8 +974,9 @@ def validate_secondary_email(account_recovery, new_email): """ Enforce valid email addresses. """ + from openedx.core.djangoapps.user_api.accounts.api import get_email_validation_error, \ - get_email_existence_validation_error, get_secondary_email_validation_error + get_secondary_email_validation_error if get_email_validation_error(new_email): raise ValueError(_('Valid e-mail address required.')) @@ -987,10 +988,13 @@ def validate_secondary_email(account_recovery, new_email): if new_email == account_recovery.user.email: raise ValueError(_('Cannot be same as your sign in email address.')) - # Make sure that secondary email address is not same as any of the primary emails. - message = get_email_existence_validation_error(new_email) - if message: - raise ValueError(message) + # Make sure that secondary email address is not same as any of the primary emails currently in use or retired + if email_exists_or_retired(new_email): + raise ValueError( + _("It looks like {email} belongs to an existing account. Try again with a different email address.").format( + email=new_email + ) + ) message = get_secondary_email_validation_error(new_email) if message: