迁移/whoami视图

This commit is contained in:
qing committed 2026-07-30 22:05:12 +08:00
1 parent 3f97dd92ef
commit 5839172dae
4 files changed
+139 -48

No files matched your search

-30
View File
@@ -279,36 +279,6 @@ def get_notes():
return jsonify(result), 200
# 当前用户身份查询:配合前端用户面板,返回 user / is_admin。
# 与 get_notes 同款可选解析:无 Token 或畸形 Token 按未登录处理(不 500)。
@app.route('/whoami', methods=["POST"])
def whoami():
info = None
auth: str = request.headers.get('Authorization', '')
if auth.startswith('Bearer '):
try:
info = decode_token(auth[7:])
except Exception:
info = None
if info is None:
return jsonify({'login': False}), 200
resp = {
'login': True,
'user': info.get('user'),
'is_admin': bool(info.get('is_admin'))
}
# 附加 Token 生命周期信息,供前端 Token 管理器估算过期时间
if info.get('iat'):
resp['iat'] = info['iat']
if info.get('created_at'):
resp['created_at'] = info['created_at']
if info.get('keep_time'):
resp['keep_time'] = info['keep_time']
return jsonify(resp), 200
# eg: {"id": 1}
@app.route('/delete_note', methods=['POST'])