- Implemented enhanced PDF parsing with V2 parser for better question extraction - Added improved question formatting and display components - Integrated question navigation and progress tracking features - Added JSON export functionality for paper questions - Enhanced image extraction and association with questions - Improved database configuration with environment variables - Updated UI with responsive question cards and navigation sidebar - Added mathematical symbol rendering and question type detection Co-authored-by: Qwen-Coder <[email protected]>
90 lines
2.8 KiB
Python
90 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
创建管理员用户脚本
|
|
用于方便测试,创建用户名admin,密码admin的账户
|
|
"""
|
|
import sys
|
|
import os
|
|
import bcrypt
|
|
from datetime import datetime
|
|
from sqlalchemy import create_engine, Column, Integer, String, DateTime
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
# 添加环境变量加载
|
|
import dotenv
|
|
dotenv.load_dotenv()
|
|
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
# 数据库配置 - 使用与 main.py 相同的配置
|
|
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://postgres:postgres@localhost:5432/wordmaster")
|
|
engine = create_engine(DATABASE_URL)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
# 导入模型(这里直接定义,避免循环导入)
|
|
Base = declarative_base()
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
username = Column(String, unique=True, index=True)
|
|
email = Column(String, unique=True, index=True)
|
|
hashed_password = Column(String)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
def get_password_hash(password: str) -> str:
|
|
"""生成密码哈希"""
|
|
return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
|
|
|
|
def create_admin_user():
|
|
"""创建管理员用户"""
|
|
# 创建数据库会话
|
|
db = SessionLocal()
|
|
|
|
try:
|
|
# 检查admin用户是否已存在
|
|
existing_admin = db.query(User).filter(User.username == "admin").first()
|
|
if existing_admin:
|
|
print("❌ admin用户已存在!")
|
|
# 更新密码为admin
|
|
existing_admin.hashed_password = get_password_hash("admin")
|
|
db.commit()
|
|
print("✅ 已更新admin用户密码为'admin'")
|
|
return
|
|
|
|
# 检查[email protected]邮箱是否已存在
|
|
existing_email = db.query(User).filter(User.email == "[email protected]").first()
|
|
if existing_email:
|
|
print("❌ [email protected]邮箱已被使用!")
|
|
return
|
|
|
|
# 创建admin用户
|
|
hashed_password = get_password_hash("admin")
|
|
admin_user = User(
|
|
username="admin",
|
|
email="[email protected]",
|
|
hashed_password=hashed_password
|
|
)
|
|
|
|
db.add(admin_user)
|
|
db.commit()
|
|
db.refresh(admin_user)
|
|
|
|
print("✅ 成功创建admin用户!")
|
|
print(" 用户名: admin")
|
|
print(" 密码: admin")
|
|
print(" 邮箱: [email protected]")
|
|
print(" ID:", admin_user.id)
|
|
|
|
except Exception as e:
|
|
print(f"❌ 创建admin用户失败: {e}")
|
|
db.rollback()
|
|
finally:
|
|
db.close()
|
|
|
|
if __name__ == "__main__":
|
|
print("🚀 开始创建admin用户...")
|
|
create_admin_user()
|
|
print("✨ 完成!") |