#!/usr/bin/env python3
"""
重置用户密码
"""

from sqlalchemy.orm import Session
from app.models.database import SessionLocal
from app.models.models import User
from app.services.user import UserService


def reset_password(username, new_password):
    """重置用户密码"""
    db = SessionLocal()
    
    try:
        # 查找用户
        user = db.query(User).filter(User.username == username).first()
        
        if user:
            # 重置密码
            user.password_hash = UserService.get_password_hash(new_password)
            db.commit()
            print(f"✅ 用户 {username} 的密码已重置为: {new_password}")
        else:
            print(f"❌ 用户 {username} 不存在")
            
    finally:
        db.close()


if __name__ == "__main__":
    # 重置admin用户的密码
    reset_password("admin", "admin123")
    
    # 重置testadmin用户的密码
    reset_password("testadmin", "admin123")
