From 48786fe31a13c3eaa5a6f68d44571865742bb71c Mon Sep 17 00:00:00 2001 From: Fantasy lee <129943055+Fantasylee21@users.noreply.github.com> Date: Sat, 12 Apr 2025 12:09:48 +0800 Subject: [PATCH] =?UTF-8?q?[chore]:=20=E6=9B=B4=E6=96=B0=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/v1/endpoints/auth.py | 12 ++++++------ app/core/config.py | 7 ++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/api/v1/endpoints/auth.py b/app/api/v1/endpoints/auth.py index 81bb525..af7ee23 100644 --- a/app/api/v1/endpoints/auth.py +++ b/app/api/v1/endpoints/auth.py @@ -90,10 +90,10 @@ def send_code(user_send_code : UserSendCode, db: Session = Depends(get_db)): code = str(random.randint(100000, 999999)) # SMTP 配置 - smtp_server = "smtp.163.com" - smtp_port = 465 - sender_email = "19855278313@163.com" # 替换为你的网易邮箱 - sender_password = "DHSihwnVc4wS89eV" # 替换为你的授权码 + smtp_server = settings.SMTP_SERVER + smtp_port = settings.SMTP_PORT + sender_email = settings.SENDER_EMAIL + sender_password = settings.SENDER_PASSWORD # 邮件内容 subject = "验证码" @@ -114,8 +114,8 @@ def send_code(user_send_code : UserSendCode, db: Session = Depends(get_db)): server.sendmail(sender_email, [user_send_code.email], message.as_string()) # 将验证码和发送时间存储到 Redis,设置 5 分钟过期时间 - redis_client.setex(f"email:{user_send_code.email}:code", 300, code) - redis_client.setex(f"email:{user_send_code.email}:time", 300, int(time.time())) + redis_client.setex(f"email:{user_send_code.email}:code", settings.ACCESS_TOKEN_EXPIRE_MINUTES, code) + redis_client.setex(f"email:{user_send_code.email}:time", settings.ACCESS_TOKEN_EXPIRE_MINUTES, int(time.time())) return {"msg": "Verification code sent"} diff --git a/app/core/config.py b/app/core/config.py index fedf166..8280afb 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -7,6 +7,11 @@ class Settings: SQLALCHEMY_DATABASE_URL = "mysql+pymysql://root:coders007@47.93.172.156:3306/JieNote" # 替换为实际的用户名、密码和数据库名称 SECRET_KEY: str = os.getenv("SECRET_KEY", "your_secret_key") # 替换为更安全的密钥 ALGORITHM: str = "HS256" # JWT算法 - ACCESS_TOKEN_EXPIRE_MINUTES: int = 30 # token过期时间 + ACCESS_TOKEN_EXPIRE_MINUTES: int = 300 # token过期时间 + SMTP_SERVER: str = "smtp.163.com" # SMTP服务器 + SMTP_PORT: int = 465 # SMTP端口 + SENDER_EMAIL : str = "jienote_buaa@163.com" + SENDER_PASSWORD: str = "TXVU2unpCAE2EtEX" + settings = Settings() \ No newline at end of file