| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- """
- 创建测试用户脚本
- 用于快速创建测试账号
- """
- import sqlite3
- import bcrypt
- from datetime import datetime
- def create_test_user():
- """创建测试用户"""
- # 连接数据库
- conn = sqlite3.connect('annotation_platform.db')
- cursor = conn.cursor()
-
- # 测试用户信息
- username = "testuser"
- email = "test@example.com"
- password = "password123"
- role = "annotator"
-
- # 检查用户是否已存在
- cursor.execute("SELECT id FROM users WHERE username = ?", (username,))
- existing_user = cursor.fetchone()
-
- if existing_user:
- print(f"用户 '{username}' 已存在,跳过创建")
- conn.close()
- return
-
- # 生成密码哈希
- password_hash = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
-
- # 生成用户 ID
- user_id = f"user_{datetime.now().strftime('%Y%m%d%H%M%S')}"
-
- # 插入用户
- cursor.execute("""
- INSERT INTO users (id, username, email, password_hash, role, created_at)
- VALUES (?, ?, ?, ?, ?, ?)
- """, (user_id, username, email, password_hash, role, datetime.now()))
-
- conn.commit()
- conn.close()
-
- print("=" * 60)
- print("测试用户创建成功!")
- print("=" * 60)
- print(f"用户名: {username}")
- print(f"密码: {password}")
- print(f"邮箱: {email}")
- print(f"角色: {role}")
- print(f"用户ID: {user_id}")
- print("=" * 60)
- print("\n现在可以使用这个账号登录前端应用了!")
- print("访问: http://localhost:4200/login")
- print("=" * 60)
- if __name__ == "__main__":
- create_test_user()
|