You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2014/07/21 12:34:29 UTC

[2/3] git commit: [#7523] add option to require an email address, which prevents deleting your last verified addr

[#7523] add option to require an email address, which prevents deleting your last verified addr


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/a707e7f2
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/a707e7f2
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/a707e7f2

Branch: refs/heads/master
Commit: a707e7f2a2ef70664e62a3dba75ecf9428401bd9
Parents: 0234737
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Wed Jul 2 20:59:49 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Jul 18 19:01:24 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py | 23 ++++++++++++++++-------
 Allura/development.ini            |  1 +
 2 files changed, 17 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/a707e7f2/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index f574730..1538c0b 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -373,6 +373,13 @@ class AuthController(BaseController):
             redirect('/')
 
 
+def select_new_primary_addr(user, ignore_emails=[]):
+    for obj_e in user.email_addresses:
+        obj = user.address_object(obj_e)
+        if obj and obj.confirmed and obj_e not in ignore_emails:
+            return obj_e
+
+
 class PreferencesController(BaseController):
 
     def _check_security(self):
@@ -407,8 +414,14 @@ class PreferencesController(BaseController):
                 obj = c.user.address_object(old_a)
                 if data.get('delete') or not obj:
                     if primary_addr == c.user.email_addresses[i]:
-                        c.user.set_pref('email_address', None)
-                        primary_addr = None
+                        if select_new_primary_addr(c.user, ignore_emails=primary_addr) is None \
+                                and asbool(config.get('auth.require_email_addr', False)):
+                            flash('You must have at least one verified email address.', 'error')
+                            redirect('.')
+                        else:
+                            # clear it now, a new one will get set below
+                            c.user.set_pref('email_address', None)
+                            primary_addr = None
                     del c.user.email_addresses[i]
                     if obj:
                         obj.delete()
@@ -423,11 +436,7 @@ class PreferencesController(BaseController):
                 else:
                     flash('Email address %s is invalid' % new_addr['addr'], 'error')
             if not primary_addr and not c.user.get_pref('email_address') and c.user.email_addresses:
-                for obj_e in c.user.email_addresses:
-                    obj = c.user.address_object(obj_e)
-                    if obj:
-                        if obj.confirmed:
-                            primary_addr = obj_e
+                primary_addr = select_new_primary_addr(c.user)
             if primary_addr:
                 c.user.set_pref('email_address', primary_addr)
             for k, v in preferences.iteritems():

http://git-wip-us.apache.org/repos/asf/allura/blob/a707e7f2/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index 3010aa6..8c5e766 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -107,6 +107,7 @@ auth.allow_edit_prefs = true
 auth.allow_password_change = true
 auth.allow_upload_ssh_key = false
 auth.allow_user_messages_config = true
+auth.require_email_addr = true
 
 # In seconds
 auth.recovery_hash_expiry_period = 600