--- web_ui.py.old	2010-05-20 09:43:45.868106653 +0800
+++ web_ui.py	2010-05-20 09:57:30.954805030 +0800
@@ -40,60 +40,66 @@
                'name' : name,
                'email' : email,
               }
-    error = TracError('')
-    error.acctmgr = acctmgr
-    if not user:
-        error.message = 'Username cannot be empty.'
-        raise error
-
-    if mgr.has_user(user):
-        error.message = 'Another account with that name already exists.'
-        raise error
-
-    if check_permissions:
-        # disallow registration of accounts which have existing permissions
-        permission_system = perm.PermissionSystem(env)
-        if permission_system.get_user_permissions(user) != \
-           permission_system.get_user_permissions('authenticated'):
+    try:
+        if not user:
+            error = TracError('')
+            error.message = 'Username cannot be empty.'
+            raise error
+
+        if mgr.has_user(user):
+            error = TracError('')
             error.message = 'Another account with that name already exists.'
             raise error
 
-    password = req.args.get('password')
-    if not password:
-        error.message = 'Password cannot be empty.'
-        raise error
-
-    if password != req.args.get('password_confirm'):
-        error.message = 'The passwords must match.'
-        raise error
-
-    mgr.set_password(user, password)
-
-    db = env.get_db_cnx()
-    cursor = db.cursor()
-    cursor.execute("SELECT count(*) FROM session "
-                   "WHERE sid=%s AND authenticated=1",
-                   (user,))
-    exists, = cursor.fetchone()
-    if not exists:
-        cursor.execute("INSERT INTO session "
-                       "(sid, authenticated, last_visit) "
-                       "VALUES (%s, 1, 0)",
-                       (user,))
+        if check_permissions:
+            # disallow registration of accounts which have existing permissions
+            permission_system = perm.PermissionSystem(env)
+            if permission_system.get_user_permissions(user) != \
+               permission_system.get_user_permissions('authenticated'):
+                error.message = 'Another account with that name already exists.'
+                raise error
+
+        password = req.args.get('password')
+        if not password:
+            error = TracError('')
+            error.message = 'Password cannot be empty.'
+            raise error
+
+        if password != req.args.get('password_confirm'):
+            error = TracError('')
+            error.message = 'The passwords must match.'
+            raise error
 
-    for key in ('name', 'email'):
-        value = req.args.get(key)
-        if not value:
-            continue
-        cursor.execute("UPDATE session_attribute SET value=%s "
-                       "WHERE name=%s AND sid=%s AND authenticated=1",
-                       (value, key, user))
-        if not cursor.rowcount:
-            cursor.execute("INSERT INTO session_attribute "
-                           "(sid,authenticated,name,value) "
-                           "VALUES (%s,1,%s,%s)",
-                           (user, key, value))
-    db.commit()
+        mgr.set_password(user, password)
+
+        db = env.get_db_cnx()
+        cursor = db.cursor()
+        cursor.execute("SELECT count(*) FROM session "
+                       "WHERE sid=%s AND authenticated=1",
+                       (user,))
+        exists, = cursor.fetchone()
+        if not exists:
+            cursor.execute("INSERT INTO session "
+                           "(sid, authenticated, last_visit) "
+                           "VALUES (%s, 1, 0)",
+                           (user,))
+
+        for key in ('name', 'email'):
+            value = req.args.get(key)
+            if not value:
+                continue
+            cursor.execute("UPDATE session_attribute SET value=%s "
+                           "WHERE name=%s AND sid=%s AND authenticated=1",
+                           (value, key, user))
+            if not cursor.rowcount:
+                cursor.execute("INSERT INTO session_attribute "
+                               "(sid,authenticated,name,value) "
+                               "VALUES (%s,1,%s,%s)",
+                               (user, key, value))
+        db.commit()
+    except TracError, e:
+        e.acctmgr = acctmgr
+        raise e
 
 
 class AccountModule(Component):
