소스 검색

时间更正

liuq 3 달 전
부모
커밋
a975764ab1
5개의 변경된 파일11개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 0
      backend/Dockerfile
  2. 2 2
      backend/app/api/v1/deps.py
  3. 2 2
      backend/app/core/security.py
  4. 1 1
      backend/app/models/operation_log.py
  5. 5 0
      docker-compose.yml

+ 1 - 0
backend/Dockerfile

@@ -16,6 +16,7 @@ RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.li
     gcc \
     default-libmysqlclient-dev \
     pkg-config \
+    tzdata \
     && rm -rf /var/lib/apt/lists/*
 
 COPY requirements.txt .

+ 2 - 2
backend/app/api/v1/deps.py

@@ -45,7 +45,7 @@ def get_current_user(
         # If token is valid but expires soon (e.g. less than half of total lifetime), renew it
         exp = payload.get("exp")
         if exp:
-            now = datetime.utcnow().timestamp()
+            now = datetime.now().timestamp()
             remaining_seconds = exp - now
             # If remaining time is less than half of the configured expiration time
             if remaining_seconds < (settings.ACCESS_TOKEN_EXPIRE_MINUTES * 60 / 2):
@@ -99,7 +99,7 @@ def get_current_user_optional(
         # Sliding Expiration Check for Optional Auth
         exp = payload.get("exp")
         if exp:
-            now = datetime.utcnow().timestamp()
+            now = datetime.now().timestamp()
             remaining_seconds = exp - now
             if remaining_seconds < (settings.ACCESS_TOKEN_EXPIRE_MINUTES * 60 / 2):
                 new_token = security.create_access_token(subject=token_data.sub)

+ 2 - 2
backend/app/core/security.py

@@ -16,9 +16,9 @@ def get_password_hash(password: str) -> str:
 
 def create_access_token(subject: Union[str, Any], expires_delta: timedelta = None) -> str:
     if expires_delta:
-        expire = datetime.utcnow() + expires_delta
+        expire = datetime.now() + expires_delta
     else:
-        expire = datetime.utcnow() + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
+        expire = datetime.now() + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
     
     to_encode = {"exp": expire, "sub": str(subject)}
     encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM)

+ 1 - 1
backend/app/models/operation_log.py

@@ -22,7 +22,7 @@ class OperationLog(Base):
     # Details (JSON for structured data like import logs, or diffs)
     details = Column(JSON, nullable=True)
     
-    created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
+    created_at = Column(DateTime, default=datetime.now, nullable=False)
 
     # Relationships
     application = relationship("Application")

+ 5 - 0
docker-compose.yml

@@ -29,6 +29,7 @@ services:
     ports:
       - "8000:8000"
     environment:
+      - TZ=Asia/Shanghai
       - MYSQL_SERVER=db
       - MYSQL_PORT=3306
       - MYSQL_USER=uap_user
@@ -59,6 +60,7 @@ services:
     command: --default-authentication-plugin=mysql_native_password
     restart: always
     environment:
+      TZ: Asia/Shanghai
       MYSQL_ROOT_PASSWORD: root_password
       MYSQL_DATABASE: uap_db
       MYSQL_USER: uap_user
@@ -94,6 +96,7 @@ services:
   hydra-migrate:
     image: oryd/hydra:v2.2.0
     environment:
+      - TZ=Asia/Shanghai
       - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
     command: migrate sql -e --yes
     depends_on:
@@ -112,6 +115,7 @@ services:
       - "5555:5555"
     command: serve -c /etc/config/hydra/hydra.yml all --dev
     environment:
+      - TZ=Asia/Shanghai
       - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
       - URLS_SELF_ISSUER=http://127.0.0.1:4444
       - URLS_CONSENT=http://localhost:5173/consent
@@ -132,6 +136,7 @@ services:
   postgresd:
     image: postgres:15
     environment:
+      - TZ=Asia/Shanghai
       - POSTGRES_USER=hydra
       - POSTGRES_PASSWORD=secret
       - POSTGRES_DB=hydra