1. Zhang Huangbin
  2. iredadmin-ose

Commits

Zhang Huangbin  committed 19b4607

Fix incorrect return value while checking domain/account existence.

  • Participants
  • Parent commits 291d2be
  • Branches default

Comments (0)

Files changed (2)

File libs/mysql/admin.py

View file
 import types
 import web
 from libs import iredutils
-from libs.mysql import core, decorators
+from libs.mysql import core, decorators, connUtils
 
 cfg = web.iredconfig
 session = web.config.get('_session')
         if not iredutils.isEmail(self.mail):
             return (False, 'INVALID_MAIL')
 
-        # Check domain exist.
+        # Check admin exist.
+        connutils = connUtils.Utils()
+        if connutils.isAdminExists(self.mail):
+            return (False, 'ALREADY_EXISTS')
 
         # Get domainGlobalAdmin setting.
         self.domainGlobalAdmin = 'yes'

File libs/mysql/connUtils.py

View file
 
     def isDomainExists(self, domain):
         if not iredutils.isDomain(domain):
-            return False
+            return True
 
         try:
             result = self.conn.select(
 
             if len(result) > 0:
                 # Exists.
-                return False
+                return True
 
             result = self.conn.select(
                 'alias_domain',
 
             if len(result) > 0:
                 # Alias domain exists.
+                return True
+            else:
+                return False
+        except:
+            # Return True as exist to not allow to create new domain/account.
+            return True
+
+    def isAdminExists(self, mail):
+        # Return True if account is invalid or exist.
+        mail = str(mail)
+        if not iredutils.isEmail(mail):
+            return True
+
+        try:
+            result = self.conn.select(
+                'admin',
+                what='username',
+                where='username = %s' % web.sqlquote(mail),
+                limit=1,
+            )
+
+            if len(result) > 0:
+                # Exists.
+                return True
+            else:
                 return False
         except:
             # Return True as exist to not allow to create new domain/account.