45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
"""直接在 Redis 中生成 admin token 用于测试"""
|
|
import asyncio
|
|
import json
|
|
import secrets
|
|
import sys
|
|
from datetime import datetime
|
|
from urllib.parse import unquote
|
|
|
|
|
|
async def main():
|
|
import redis.asyncio as redis_async
|
|
|
|
# 连接到 Redis 容器(使用生产密码)
|
|
redis_url = "redis://:WKzl7jgKTkeWxFWGIBXfzokm59Gvfr76@localhost:6379/0"
|
|
redis_client = redis_async.from_url(redis_url)
|
|
|
|
# 构造 admin 用户的 token
|
|
token = secrets.token_urlsafe(32)
|
|
user_info = {
|
|
"employee_id": "admin_test_001",
|
|
"username": "admin",
|
|
"name": "测试管理员",
|
|
"role": "admin",
|
|
"department": "IT支持组",
|
|
"login_source": "test",
|
|
"login_method": "test_script",
|
|
"last_active": datetime.now().isoformat(),
|
|
}
|
|
|
|
# 写入 Redis
|
|
token_key = f"user:token:{token}"
|
|
await redis_client.setex(token_key, 8 * 3600, json.dumps(user_info, ensure_ascii=False))
|
|
|
|
print(f"TOKEN={token}")
|
|
|
|
# 验证
|
|
val = await redis_client.get(token_key)
|
|
print(f"VERIFIED={val is not None}")
|
|
|
|
await redis_client.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|