Anonymous avatar Anonymous committed 4846958

Require email verification fixes and improvements, patch from http://trac-hacks.org/ticket/5509 by dake and izzy

Comments (0)

Files changed (3)

         """Returns whether the user account exists.
         """
 
+    def address_exists(self, address):
+        """Returns whether a user account with the email address exists.
+        """
+
     def set_password(self, user, password):
         """Sets the password for the user.  This should create the user account
         if it doesn't already exist.
             continue
         return exists
 
+    def address_exists(self, address):
+        """Check db directly - email addresses are not backend-specific.
+        """
+        db = self.env.get_db_cnx()
+        cursor = db.cursor()
+        cursor.execute("SELECT value FROM session_attribute "
+                       "WHERE authenticated=1 AND name='email' "
+                       "AND value=%s", (address,))
+        for row in cursor:
+            return True
+        return False
+
     def set_password(self, user, password):
         store = self.find_user_store(user)
         if store and not hasattr(store, 'set_password'):

acct_mgr/templates/register.html

                      class="textwidget" size="20" />
             </label>
           </div>
+          <div py:if="verification_enabled">
+            <label>Email:
+              <input type="text" name="email" class="textwidget" size="20"  value="${acctmgr.email}"/>
+            </label>
+          </div>
         </fieldset>
         <fieldset>
           <legend>Optional</legend>
               <input type="text" name="name" class="textwidget" size="20"  value="${acctmgr.name}"/>
             </label>
           </div>
-          <div>
+          <div py:if="not verification_enabled">
             <label>Email:
               <input type="text" name="email" class="textwidget" size="20"  value="${acctmgr.email}"/>
             </label>

acct_mgr/web_ui.py

 import random
 import string
 import time
+import re
 
 from trac import perm, util
 from trac.core import *
         error.message = 'Another account with that name already exists.'
         raise error
 
+    if if_enabled(EmailVerificationModule):
+        if not email:
+           error.message = 'You must specify a valid email address.'
+           raise error
+        elif not re.match('^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$',email,re.I):
+           error.message = 'The email address specified appears to be invalid. Please specify a valid email address.'
+           raise error
+        elif mgr.address_exists(email):
+           error.message = 'The email address specified is already in use. Please specify a different address.'
+           raise error
+
     if check_permissions:
         # disallow registration of accounts which have existing permissions
         permission_system = perm.PermissionSystem(env)
                               'email' : None,
                             },
                 }
+        data['verification_enabled'] = self.env.is_component_enabled(EmailVerificationModule)
         if req.method == 'POST' and action == 'create':
             try:
                 _create_user(req, self.env)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.