Index: uc_users.py
===================================================================
--- uc_users.py	(revision 95cf703d2ef8f7abf8a3684935be560cdf73467f)
+++ uc_users.py	(revision 527c0976508c7d2fad14e9180bcf1a211d5f18af)
@@ -3,5 +3,5 @@
 import bcrypt
 
-from db import get_connection, pick_from_list
+from db import get_connection, get_transaction, pick_from_list
 
 
@@ -40,14 +40,5 @@
         return
 
-    # Step 3: Check email uniqueness
-    with get_connection() as conn:
-        with conn.cursor() as cur:
-            cur.execute("SELECT COUNT(*) FROM users WHERE email = %s", (email,))
-            exists = cur.fetchone()[0]
-    if exists > 0:
-        print(f"\n  ERROR: A user with email '{email}' already exists.")
-        return
-
-    # Step 4: Enter password
+    # Step 3: Enter password
     password = getpass.getpass("  Initial password: ").strip()
     if not password:
@@ -59,22 +50,28 @@
         return
 
-    # Step 5: Hash and insert
+    # Step 4: Hash password
     hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
 
-    conn = get_connection()
+    # Step 5: Transaction — check email uniqueness + insert atomically
+    # This prevents a race condition where two users register with the
+    # same email simultaneously (one check passes, both insert).
     try:
-        with conn.cursor() as cur:
-            cur.execute(
-                """
-                INSERT INTO users (first_name, last_name, email, password, type_id)
-                VALUES (%s, %s, %s, %s, %s)
-                RETURNING user_id, first_name, last_name, email
-                """,
-                (first_name, last_name, email, hashed, type_id),
-            )
-            result = cur.fetchone()
-        conn.commit()
+        with get_transaction() as conn:
+            with conn.cursor() as cur:
+                cur.execute("SELECT COUNT(*) FROM users WHERE email = %s", (email,))
+                if cur.fetchone()[0] > 0:
+                    raise ValueError(f"A user with email '{email}' already exists.")
 
-        # Step 6: Confirmation
+                cur.execute(
+                    """
+                    INSERT INTO users (first_name, last_name, email, password, type_id)
+                    VALUES (%s, %s, %s, %s, %s)
+                    RETURNING user_id, first_name, last_name, email
+                    """,
+                    (first_name, last_name, email, hashed, type_id),
+                )
+                result = cur.fetchone()
+
+        # Transaction committed automatically — Step 6: Confirmation
         print(f"\n  User created successfully!")
         print(f"  User ID:  {result[0]}")
@@ -82,7 +79,6 @@
         print(f"  Email:    {result[3]}")
         print(f"  Role:     {role_name}")
+    except ValueError as e:
+        print(f"\n  ERROR: {e}")
     except Exception as e:
-        conn.rollback()
         print(f"\n  Error creating user: {e}")
-    finally:
-        conn.close()
