Files
TEMP_spec_system_V3/update_admin.py
beabigegg 4f7f46b07a 2ND
2025-08-28 08:59:46 +08:00

37 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""
更新使用者權限為管理員的腳本
"""
from models import db, User
from app import app
def update_user_to_admin(username):
"""將指定使用者設為管理員權限"""
with app.app_context():
user = User.query.filter_by(username=username).first()
if user:
print(f'找到使用者: {user.username}')
print(f'當前權限: {user.role}')
if user.role != 'admin':
user.role = 'admin'
db.session.commit()
print(f'權限已更新為: {user.role}')
else:
print('使用者已經是管理員權限')
return True
else:
print(f'使用者 {username} 不存在')
return False
if __name__ == "__main__":
username = 'ymirliu@panjit.com.tw'
print(f"正在更新使用者 {username} 的權限...")
success = update_user_to_admin(username)
if success:
print("\n管理員權限設定完成!")
else:
print("\n請先使用該帳號登入一次以建立使用者記錄")