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

[8/8] git commit: [#7436] ticket:601 Validate emails and fix saving by hitting Enter

[#7436] ticket:601 Validate emails and fix saving by hitting Enter


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

Branch: refs/heads/master
Commit: f80727e01b2d91f8d0b7d9a94d3fb7ac8eab84a4
Parents: 88ef1d4
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Jun 12 13:32:19 2014 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Jun 12 19:38:42 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py             | 9 ++++++---
 Allura/allura/templates/jinja_master/lib.html | 4 ++--
 Allura/allura/templates/user_prefs.html       | 9 +++++++++
 3 files changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/f80727e0/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index b7b35ae..92b618b 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -43,6 +43,7 @@ from allura.lib.widgets import (
     ForgottenPasswordForm,
     DisableAccountForm)
 from allura.lib.widgets import forms
+from allura.lib import mail_util
 from allura.controllers import BaseController
 
 log = logging.getLogger(__name__)
@@ -372,14 +373,16 @@ class PreferencesController(BaseController):
                     del c.user.email_addresses[i]
                     if obj:
                         obj.delete()
-            if new_addr.get('claim'):
-                if M.EmailAddress.query.get(_id=new_addr['addr'], confirmed=True):
+            if new_addr.get('claim') or new_addr.get('addr'):
+                if M.EmailAddress.query.get(_id=new_addr['addr']):
                     flash('Email address already claimed', 'error')
-                else:
+                elif mail_util.isvalid(new_addr['addr']):
                     c.user.email_addresses.append(new_addr['addr'])
                     em = M.EmailAddress.upsert(new_addr['addr'])
                     em.claimed_by_user_id = c.user._id
                     em.send_verification_link()
+                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:
                 primary_addr = c.user.email_addresses[0]
             if primary_addr:

http://git-wip-us.apache.org/repos/asf/allura/blob/f80727e0/Allura/allura/templates/jinja_master/lib.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/lib.html b/Allura/allura/templates/jinja_master/lib.html
index c227dff..229c351 100644
--- a/Allura/allura/templates/jinja_master/lib.html
+++ b/Allura/allura/templates/jinja_master/lib.html
@@ -138,8 +138,8 @@
            {% if option == value %}checked{% endif %}/><br/>
 {% endmacro %}
 
-{% macro submit_button(value, name=None) %}
-    <input type="submit" name="{{name}}" value="{{value}}"/><br/>
+{% macro submit_button(value, name=None, style=None) %}
+  <input type="submit" name="{{name}}" value="{{value}}" style="{{style}}"/><br/>
 {% endmacro %}
 
 {% macro abbr_date(start_time) %}

http://git-wip-us.apache.org/repos/asf/allura/blob/f80727e0/Allura/allura/templates/user_prefs.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/user_prefs.html b/Allura/allura/templates/user_prefs.html
index 61b4a87..4d86591 100644
--- a/Allura/allura/templates/user_prefs.html
+++ b/Allura/allura/templates/user_prefs.html
@@ -60,6 +60,15 @@
           {% for a in c.user.email_addresses %}
             <input name="addr-{{loop.index0}}.ord" value="{{loop.index0}}" type="hidden"/>
           {% endfor %}
+          {#
+           # This is a hidden copy of a 'Save' submit button.
+           # We need this because form uses several submit buttons, and
+           # if user presses 'Enter' in one of the fields, browser chooses *first* submit button.
+           # In the case when user has at least one email address, first button is delete button
+           # for first email address. So user ends up deleting their first email address,
+           # instead of changing display name, for example.
+           #}
+          {{lib.submit_button('Save', style='display:none')}}
           <hr>
           <h3>Email Addresses</h3>
           <table class="grid-22">