From 00b0baabbb2a54bf544ed2f18d71d77077b51f51 Mon Sep 17 00:00:00 2001
From: Saleem Latif <saleem_ee@hotmail.com>
Date: Fri, 8 Feb 2019 15:55:07 +0500
Subject: [PATCH] Updating recovery email address from an already verified
 email address auto verifies the new address

---
 common/djangoapps/student/models.py              | 11 +++++++++++
 openedx/core/djangoapps/user_api/accounts/api.py |  3 +--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py
index 798f2321025..214c8d8a97d 100644
--- a/common/djangoapps/student/models.py
+++ b/common/djangoapps/student/models.py
@@ -2750,3 +2750,14 @@ class AccountRecovery(models.Model):
         db_table = "auth_accountrecovery"
 
     objects = AccountRecoveryManager()
+
+    def update_recovery_email(self, email):
+        """
+        Update the secondary email address on the instance to the email in the argument.
+
+        Arguments:
+            email (str): New email address to be set as the secondary email address.
+        """
+        self.secondary_email = email
+        self.is_active = False
+        self.save()
diff --git a/openedx/core/djangoapps/user_api/accounts/api.py b/openedx/core/djangoapps/user_api/accounts/api.py
index d1c09f312cc..d49cfe83672 100644
--- a/openedx/core/djangoapps/user_api/accounts/api.py
+++ b/openedx/core/djangoapps/user_api/accounts/api.py
@@ -209,8 +209,7 @@ def update_account_settings(requesting_user, update, username=None):
                 "user_message": text_type(err)
             }
         else:
-            account_recovery.secondary_email = update["secondary_email"]
-            account_recovery.save()
+            account_recovery.update_recovery_email(update["secondary_email"])
 
     # If the user asked to change full name, validate it
     if changing_full_name:
-- 
GitLab