fix(用户管理): 修改用户创建的时间逻辑为UTC+8 (#63)
将用户创建和密码重置的时间获取和格式化逻辑修改为使用UTC+8时区(Asia/Shanghai),以确保时间存储的一致性。此修改避免了不同时区用户时间显示不一致的问题。
This commit is contained in:
parent
94953687c1
commit
8a9d6a30f6
|
@ -3,50 +3,13 @@ description: Propose a feature request for RAGFlow-Plus.
|
|||
title: "[Feature Request]: "
|
||||
labels: ["💞 feature"]
|
||||
body:
|
||||
- type: checkboxes
|
||||
- type: markdown
|
||||
attributes:
|
||||
label: Self Checks
|
||||
description: "Please check the following in order to be responded in time :)"
|
||||
options:
|
||||
- label: I have searched for existing issues [search for existing issues](https://github.com/infiniflow/ragflow/issues), including closed ones.
|
||||
required: true
|
||||
- label: I confirm that I am using English to submit this report ([Language Policy](https://github.com/infiniflow/ragflow/issues/5910)).
|
||||
required: true
|
||||
- label: Non-english title submitions will be closed directly ( 非英文标题的提交将会被直接关闭 ) ([Language Policy](https://github.com/infiniflow/ragflow/issues/5910)).
|
||||
required: true
|
||||
- label: "Please do not modify this template :) and fill in all the required fields."
|
||||
required: true
|
||||
value: |
|
||||
请尽可能详细地描述你的需求。
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Is your feature request related to a problem?
|
||||
description: |
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
render: Markdown
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Describe the feature you'd like
|
||||
description: A clear and concise description of what you want to happen.
|
||||
label: 描述你想要的新功能
|
||||
description: 尽可能结合业务场景,清晰地描述
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Describe implementation you've considered
|
||||
description: A clear and concise description of implementation you've considered or investigated.
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Documentation, adoption, use case
|
||||
description: If you can, explain some scenarios how users might use this, situations it would be helpful in. Any API designs, mockups, or diagrams are also helpful.
|
||||
render: Markdown
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional information
|
||||
description: |
|
||||
Add any other context or screenshots about the feature request here.
|
||||
validations:
|
||||
required: false
|
|
@ -12,3 +12,4 @@ elasticsearch==8.12.0
|
|||
minio==7.2.4
|
||||
strenum==0.4.15
|
||||
peewee==3.17.1
|
||||
pytz==2020.5
|
|
@ -1,4 +1,5 @@
|
|||
import mysql.connector
|
||||
import pytz
|
||||
from datetime import datetime
|
||||
from utils import generate_uuid, encrypt_password
|
||||
from database import DB_CONFIG
|
||||
|
@ -97,7 +98,10 @@ def delete_user(user_id):
|
|||
return False
|
||||
|
||||
def create_user(user_data):
|
||||
"""创建新用户,并加入最早用户的团队,并使用相同的模型配置"""
|
||||
"""
|
||||
创建新用户,并加入最早用户的团队,并使用相同的模型配置。
|
||||
时间将以 UTC+8 (Asia/Shanghai) 存储。
|
||||
"""
|
||||
try:
|
||||
conn = mysql.connector.connect(**DB_CONFIG)
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
|
@ -146,9 +150,18 @@ def create_user(user_data):
|
|||
# 加密密码
|
||||
encrypted_password = encrypt_password(password)
|
||||
|
||||
current_datetime = datetime.now()
|
||||
create_time = int(current_datetime.timestamp() * 1000)
|
||||
current_date = current_datetime.strftime("%Y-%m-%d %H:%M:%S")
|
||||
# --- 修改时间获取和格式化逻辑 ---
|
||||
# 获取当前 UTC 时间
|
||||
utc_now = datetime.utcnow().replace(tzinfo=pytz.utc)
|
||||
# 定义目标时区 (UTC+8)
|
||||
target_tz = pytz.timezone('Asia/Shanghai')
|
||||
# 将 UTC 时间转换为目标时区时间
|
||||
local_dt = utc_now.astimezone(target_tz)
|
||||
|
||||
# 使用转换后的时间
|
||||
create_time = int(local_dt.timestamp() * 1000) # 使用本地化时间戳
|
||||
current_date = local_dt.strftime("%Y-%m-%d %H:%M:%S") # 使用本地化时间格式化
|
||||
# --- 时间逻辑修改结束 ---
|
||||
|
||||
# 插入用户表
|
||||
user_insert_query = """
|
||||
|
@ -165,9 +178,9 @@ def create_user(user_data):
|
|||
)
|
||||
"""
|
||||
user_data_tuple = (
|
||||
user_id, create_time, current_date, create_time, current_date, None,
|
||||
user_id, create_time, current_date, create_time, current_date, None, # 使用修改后的时间
|
||||
username, encrypted_password, email, None, "Chinese", "Bright", "UTC+8 Asia/Shanghai",
|
||||
current_date, 1, 1, 0, "password",
|
||||
current_date, 1, 1, 0, "password", # last_login_time 也使用 UTC+8 时间
|
||||
1, 0
|
||||
)
|
||||
cursor.execute(user_insert_query, user_data_tuple)
|
||||
|
@ -188,7 +201,7 @@ def create_user(user_data):
|
|||
if user_count > 0:
|
||||
# 如果有现有用户,复制其模型配置
|
||||
tenant_data = (
|
||||
user_id, create_time, current_date, create_time, current_date, username + "'s Kingdom",
|
||||
user_id, create_time, current_date, create_time, current_date, username + "'s Kingdom", # 使用修改后的时间
|
||||
None, str(earliest_tenant['llm_id']), str(earliest_tenant['embd_id']),
|
||||
str(earliest_tenant['asr_id']), str(earliest_tenant['img2txt_id']),
|
||||
str(earliest_tenant['rerank_id']), str(earliest_tenant['tts_id']),
|
||||
|
@ -197,7 +210,7 @@ def create_user(user_data):
|
|||
else:
|
||||
# 如果是第一个用户,模型ID使用空字符串
|
||||
tenant_data = (
|
||||
user_id, create_time, current_date, create_time, current_date, username + "'s Kingdom",
|
||||
user_id, create_time, current_date, create_time, current_date, username + "'s Kingdom", # 使用修改后的时间
|
||||
None, '', '', '', '', '', '',
|
||||
'', "1000", 1
|
||||
)
|
||||
|
@ -214,7 +227,7 @@ def create_user(user_data):
|
|||
)
|
||||
"""
|
||||
user_tenant_data_owner = (
|
||||
generate_uuid(), create_time, current_date, create_time, current_date, user_id,
|
||||
generate_uuid(), create_time, current_date, create_time, current_date, user_id, # 使用修改后的时间
|
||||
user_id, "owner", user_id, 1
|
||||
)
|
||||
cursor.execute(user_tenant_insert_owner_query, user_tenant_data_owner)
|
||||
|
@ -232,7 +245,7 @@ def create_user(user_data):
|
|||
)
|
||||
"""
|
||||
user_tenant_data_normal = (
|
||||
generate_uuid(), create_time, current_date, create_time, current_date, user_id,
|
||||
generate_uuid(), create_time, current_date, create_time, current_date, user_id, # 使用修改后的时间
|
||||
earliest_tenant['id'], "normal", earliest_tenant['id'], 1
|
||||
)
|
||||
cursor.execute(user_tenant_insert_normal_query, user_tenant_data_normal)
|
||||
|
@ -251,7 +264,7 @@ def create_user(user_data):
|
|||
# 遍历最早用户的所有tenant_llm配置并复制给新用户
|
||||
for tenant_llm in earliest_user_tenant_llms:
|
||||
tenant_llm_data = (
|
||||
create_time, current_date, create_time, current_date, user_id,
|
||||
create_time, current_date, create_time, current_date, user_id, # 使用修改后的时间
|
||||
str(tenant_llm['llm_factory']), str(tenant_llm['model_type']), str(tenant_llm['llm_name']),
|
||||
str(tenant_llm['api_key']), str(tenant_llm['api_base']), str(tenant_llm['max_tokens']), 0
|
||||
)
|
||||
|
@ -291,7 +304,8 @@ def update_user(user_id, user_data):
|
|||
|
||||
def reset_user_password(user_id, new_password):
|
||||
"""
|
||||
重置指定用户的密码
|
||||
重置指定用户的密码。
|
||||
时间将以 UTC+8 (Asia/Shanghai) 存储。
|
||||
Args:
|
||||
user_id (str): 用户ID
|
||||
new_password (str): 新的明文密码
|
||||
|
@ -304,8 +318,19 @@ def reset_user_password(user_id, new_password):
|
|||
|
||||
# 加密新密码
|
||||
encrypted_password = encrypt_password(new_password) # 使用与创建用户时相同的加密方法
|
||||
update_time = int(datetime.now().timestamp() * 1000)
|
||||
update_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# --- 修改时间获取和格式化逻辑 ---
|
||||
# 获取当前 UTC 时间
|
||||
utc_now = datetime.utcnow().replace(tzinfo=pytz.utc)
|
||||
# 定义目标时区 (UTC+8)
|
||||
target_tz = pytz.timezone('Asia/Shanghai')
|
||||
# 将 UTC 时间转换为目标时区时间
|
||||
local_dt = utc_now.astimezone(target_tz)
|
||||
|
||||
# 使用转换后的时间
|
||||
update_time = int(local_dt.timestamp() * 1000) # 使用本地化时间戳
|
||||
update_date = local_dt.strftime("%Y-%m-%d %H:%M:%S") # 使用本地化时间格式化
|
||||
# --- 时间逻辑修改结束 ---
|
||||
|
||||
# 更新用户密码
|
||||
update_query = """
|
||||
|
|
|
@ -109,7 +109,6 @@ graspologic>=3.4.1,<4.0.0
|
|||
pymysql>=1.1.1,<2.0.0
|
||||
mini-racer>=0.12.4,<0.13.0
|
||||
pyodbc>=5.2.0,<6.0.0
|
||||
pyicu>=2.13.1,<3.0.0
|
||||
flasgger>=0.9.7.1,<0.10.0
|
||||
xxhash>=3.5.0,<4.0.0
|
||||
trio>=0.29.0
|
Loading…
Reference in New Issue