Spaces:
Sleeping
Sleeping
Upload api_auth.py
Browse files- api_auth.py +10 -3
api_auth.py
CHANGED
|
@@ -18,7 +18,6 @@ async def register(req: AuthReq):
|
|
| 18 |
if any(isinstance(info, dict) and str(info.get("phone", "")).strip() == safe_phone for info in users.values()):
|
| 19 |
return {"status": "error", "message": "手机号已被绑定"}
|
| 20 |
|
| 21 |
-
# 🌟 优化 6:使用军事级 bcrypt 盐值哈希加密密码
|
| 22 |
pwd_hash = bcrypt.hashpw(req.password.encode(), bcrypt.gensalt()).decode()
|
| 23 |
reg_date = datetime.now().strftime("%Y-%m-%d")
|
| 24 |
|
|
@@ -36,7 +35,6 @@ async def login(req: AuthReq):
|
|
| 36 |
|
| 37 |
user_info = users[actual_user]
|
| 38 |
|
| 39 |
-
# 🌟 优化 6 平滑过渡:允许老版 MD5 账号登录,并在验证成功后静默热升级为 bcrypt
|
| 40 |
is_valid = False
|
| 41 |
if len(user_info["password_hash"]) == 32:
|
| 42 |
import hashlib
|
|
@@ -145,4 +143,13 @@ def _cascade_update_username(old_name, new_name):
|
|
| 145 |
if r.get("user") == old_name:
|
| 146 |
r["user"] = new_name
|
| 147 |
changed_pls = True
|
| 148 |
-
if changed_pls: save_db(pls, "cloud_playlists.json")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
if any(isinstance(info, dict) and str(info.get("phone", "")).strip() == safe_phone for info in users.values()):
|
| 19 |
return {"status": "error", "message": "手机号已被绑定"}
|
| 20 |
|
|
|
|
| 21 |
pwd_hash = bcrypt.hashpw(req.password.encode(), bcrypt.gensalt()).decode()
|
| 22 |
reg_date = datetime.now().strftime("%Y-%m-%d")
|
| 23 |
|
|
|
|
| 35 |
|
| 36 |
user_info = users[actual_user]
|
| 37 |
|
|
|
|
| 38 |
is_valid = False
|
| 39 |
if len(user_info["password_hash"]) == 32:
|
| 40 |
import hashlib
|
|
|
|
| 143 |
if r.get("user") == old_name:
|
| 144 |
r["user"] = new_name
|
| 145 |
changed_pls = True
|
| 146 |
+
if changed_pls: save_db(pls, "cloud_playlists.json")
|
| 147 |
+
|
| 148 |
+
# 🌟 新增:统计社区总人数的接口
|
| 149 |
+
@router.get("/api/hub/stats")
|
| 150 |
+
async def get_hub_stats():
|
| 151 |
+
try:
|
| 152 |
+
users = get_db("users.json")
|
| 153 |
+
return {"status": "success", "user_count": len(users)}
|
| 154 |
+
except Exception as e:
|
| 155 |
+
return {"status": "error", "message": str(e)}
|