Spaces:
Running
Running
Upload 2 files
Browse files- router_proxy.py +1 -1
- router_users.py +34 -0
router_proxy.py
CHANGED
|
@@ -40,7 +40,7 @@ async def proxy_github_zip(req_data: ProxyGithubZipRequest, db: Session = Depend
|
|
| 40 |
owner, repo = repo_parts[-2], repo_parts[-1]
|
| 41 |
|
| 42 |
# GitHub 官方提供的打包下载 API
|
| 43 |
-
github_zip_api = f"https://api.github.com/repos/{owner}/{repo}/zipball
|
| 44 |
|
| 45 |
# 【核心修改】:优先读取该资源在数据库中绑定的专属创作者 Token
|
| 46 |
creator_token = item.get("github_token")
|
|
|
|
| 40 |
owner, repo = repo_parts[-2], repo_parts[-1]
|
| 41 |
|
| 42 |
# GitHub 官方提供的打包下载 API
|
| 43 |
+
github_zip_api = f"https://api.github.com/repos/{owner}/{repo}/zipball"
|
| 44 |
|
| 45 |
# 【核心修改】:优先读取该资源在数据库中绑定的专属创作者 Token
|
| 46 |
creator_token = item.get("github_token")
|
router_users.py
CHANGED
|
@@ -197,6 +197,40 @@ async def login_user(user: UserLogin):
|
|
| 197 |
if user_data.get("password") != user.password: raise HTTPException(status_code=401, detail="密码错误")
|
| 198 |
return {"status": "success", "token": f"mock_token_{user.account}", "account": user.account, "name": user_data["name"], "avatar": user_data.get("avatarDataUrl", "https://via.placeholder.com/150")}
|
| 199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
@router.get("/api/users/{account}")
|
| 201 |
async def get_user_profile(account: str):
|
| 202 |
users_db = db.load_data("users.json", default_data={})
|
|
|
|
| 197 |
if user_data.get("password") != user.password: raise HTTPException(status_code=401, detail="密码错误")
|
| 198 |
return {"status": "success", "token": f"mock_token_{user.account}", "account": user.account, "name": user_data["name"], "avatar": user_data.get("avatarDataUrl", "https://via.placeholder.com/150")}
|
| 199 |
|
| 200 |
+
# ==========================================
|
| 201 |
+
# 补充:发送验证码的 API 接口
|
| 202 |
+
# ==========================================
|
| 203 |
+
@router.post("/api/users/send_code")
|
| 204 |
+
async def send_code_api(req: SendCodeRequest):
|
| 205 |
+
# 1. 生成 6 位随机数字验证码
|
| 206 |
+
code = str(random.randint(100000, 999999))
|
| 207 |
+
|
| 208 |
+
# 2. 生成缓存 Key (格式: 邮箱地址_动作)
|
| 209 |
+
# 例如: test@qq.com_register 或 test@qq.com_reset
|
| 210 |
+
key = f"{req.contact}_{req.action_type}"
|
| 211 |
+
|
| 212 |
+
# 3. 存入全局内存字典 (设置有效期为 10 分钟 = 600 秒)
|
| 213 |
+
VERIFY_CODES[key] = {
|
| 214 |
+
"code": code,
|
| 215 |
+
"expires": time.time() + 600
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
# 4. 触发发送逻辑
|
| 219 |
+
if req.contact_type == "email":
|
| 220 |
+
try:
|
| 221 |
+
# 调用你文件里已经写好的通过 Make.com Webhook 发邮件的函数
|
| 222 |
+
send_email_code(req.contact, code, req.action_type)
|
| 223 |
+
return {"status": "success", "message": "验证码已成功发送至邮箱"}
|
| 224 |
+
except Exception as e:
|
| 225 |
+
raise HTTPException(status_code=500, detail=f"邮件发送失败: {str(e)}")
|
| 226 |
+
|
| 227 |
+
elif req.contact_type == "phone":
|
| 228 |
+
# 预留的短信通道
|
| 229 |
+
return {"status": "success", "message": "验证码已成功发送至手机"}
|
| 230 |
+
|
| 231 |
+
else:
|
| 232 |
+
raise HTTPException(status_code=400, detail="不支持的验证方式")
|
| 233 |
+
|
| 234 |
@router.get("/api/users/{account}")
|
| 235 |
async def get_user_profile(account: str):
|
| 236 |
users_db = db.load_data("users.json", default_data={})
|