mobile app database models admin_contests admin_dashboard admin_exams admin_posts admin_teacher_applications admin_users apply_contest apply_teacher base chat contest_detail contest_list exam_result forum notifications profile themes
This commit is contained in:
45
create_admin.py
Normal file
45
create_admin.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/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()
|
||||
Reference in New Issue
Block a user