46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""创建管理员账号脚本"""
|
|
|
|
from app import app, db
|
|
from models import User
|
|
|
|
def create_admin():
|
|
with app.app_context():
|
|
# 检查邮箱是否已存在
|
|
existing_user = User.query.filter_by(email='1512344589@qq.com').first()
|
|
if existing_user:
|
|
print(f'邮箱 1512344589@qq.com 已存在')
|
|
print(f'用户名: {existing_user.name}')
|
|
print(f'角色: {existing_user.role}')
|
|
|
|
# 更新为管理员
|
|
if existing_user.role != 'admin':
|
|
existing_user.role = 'admin'
|
|
existing_user.password = '1'
|
|
db.session.commit()
|
|
print('已将该用户更新为管理员')
|
|
else:
|
|
print('该用户已经是管理员')
|
|
return
|
|
|
|
# 创建新管理员
|
|
admin = User(
|
|
name='管理员',
|
|
email='1512344589@qq.com',
|
|
password='1',
|
|
role='admin'
|
|
)
|
|
|
|
db.session.add(admin)
|
|
db.session.commit()
|
|
|
|
print('管理员账号创建成功!')
|
|
print(f'邮箱: {admin.email}')
|
|
print(f'密码: 1')
|
|
print(f'角色: {admin.role}')
|
|
print(f'用户ID: {admin.id}')
|
|
|
|
if __name__ == '__main__':
|
|
create_admin()
|