Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/api/v1/endpoints/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "验证码"
Expand All @@ -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"}

Expand Down
7 changes: 6 additions & 1 deletion app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()