feat: log
This commit is contained in:
17
run.py
17
run.py
@@ -1,3 +1,4 @@
|
||||
"""应用启动入口"""
|
||||
import os
|
||||
import click
|
||||
from app import create_app, db
|
||||
@@ -13,23 +14,23 @@ def make_shell_context():
|
||||
@click.argument("username")
|
||||
@click.argument("email")
|
||||
@click.argument("password")
|
||||
@click.option("--admin", is_flag=True, help="Flag to create an admin user.")
|
||||
@click.option("--admin", is_flag=True, help="创建管理员用户")
|
||||
def create_user(username, email, password, admin):
|
||||
"""Creates a new user."""
|
||||
"""创建新用户"""
|
||||
if User.query.filter_by(email=email).first():
|
||||
print(f"Error: Email {email} already exists.")
|
||||
print(f"错误: 邮箱 {email} 已存在")
|
||||
return
|
||||
if User.query.filter_by(username=username).first():
|
||||
print(f"Error: Username {username} already exists.")
|
||||
print(f"错误: 用户名 {username} 已存在")
|
||||
return
|
||||
|
||||
|
||||
user = User(username=username, email=email, status='active')
|
||||
user.set_password(password)
|
||||
if admin:
|
||||
user.role = 'admin'
|
||||
|
||||
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
print(f"User {username} created successfully.")
|
||||
print(f"用户 {username} 创建成功")
|
||||
if admin:
|
||||
print("Role: Admin")
|
||||
print("角色: 管理员")
|
||||
|
||||
Reference in New Issue
Block a user