Przeglądaj źródła

Fix the problem of database access failure during user registration.

wangxq 2 miesięcy temu
rodzic
commit
f1cbb31560
1 zmienionych plików z 15 dodań i 5 usunięć
  1. 15 5
      app/core/system/auth.py

+ 15 - 5
app/core/system/auth.py

@@ -9,6 +9,8 @@ import time
 import uuid
 import psycopg2
 from psycopg2 import pool
+from urllib.parse import urlparse
+from app.config.config import Config
 
 logger = logging.getLogger(__name__)
 
@@ -26,14 +28,22 @@ def get_pg_connection():
     
     if pg_pool is None:
         try:
+            # 解析SQLAlchemy URI
+            uri = urlparse(Config.SQLALCHEMY_DATABASE_URI)
+            username = uri.username
+            password = uri.password
+            database = uri.path[1:]  # 移除开头的 '/'
+            hostname = uri.hostname
+            port = uri.port or 5432
+            
             # 创建连接池
             pg_pool = psycopg2.pool.SimpleConnectionPool(
                 1, 20,
-                host="localhost",
-                database="dataops",
-                user="postgres",
-                password="postgres",
-                port="5432"
+                host=hostname,
+                database=database,
+                user=username,
+                password=password,
+                port=str(port)
             )
             logger.info("PostgreSQL连接池初始化成功")
         except Exception as e: