Anonymous committed 4846958

Require email verification fixes and improvements, patch from 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.
         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'):


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


 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':
                 _create_user(req, self.env)