2ND
This commit is contained in:
37
update_admin.py
Normal file
37
update_admin.py
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/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請先使用該帳號登入一次以建立使用者記錄")
|
Reference in New Issue
Block a user