Files
zsglpt/fix_quick_login.py
Yu Yon b5344cd55e 修复所有bug并添加新功能
- 修复添加账号按钮无反应问题
- 添加账号备注字段(可选)
- 添加账号设置按钮(修改密码/备注)
- 修复用户反馈���能
- 添加定时任务执行日志
- 修复容器重启后账号加载问题
- 修复所有JavaScript语法错误
- 优化账号加载机制(4层保障)

🤖 Generated with Claude Code
2025-12-10 11:19:16 +08:00

93 lines
3.7 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""修复quick_login - 使用池中浏览器时直接登录不尝试加载cookies"""
import re
with open('/www/wwwroot/zsglpt/playwright_automation.py', 'r', encoding='utf-8') as f:
content = f.read()
# 修复 quick_login 方法 - 当已有浏览器时直接登录
old_quick_login = ''' def quick_login(self, username: str, password: str, remember: bool = True):
"""快速登录 - 优先使用cookies失败则正常登录"""
# 尝试使用cookies
if self.load_cookies(username):
self.log(f"尝试使用已保存的登录态...")
if self.check_login_state():
self.log(f"✓ 登录态有效,跳过登录")
return {"success": True, "message": "使用已保存的登录态", "used_cookies": True}
else:
self.log(f"登录态已失效,重新登录")
# 关闭当前context重新登录
try:
if self.context:
self.context.close()
if self.browser:
self.browser.close()
if self.playwright:
self.playwright.stop()
except:
pass
# 正常登录
result = self.login(username, password, remember)
# 登录成功后保存cookies
if result.get('success'):
self.save_cookies(username)
result['used_cookies'] = False
return result'''
new_quick_login = ''' def quick_login(self, username: str, password: str, remember: bool = True):
"""快速登录 - 使用池中浏览器时直接登录否则尝试cookies"""
# 如果已有浏览器实例(从池中获取),直接使用该浏览器登录
# 不尝试加载cookies因为load_cookies会创建新浏览器覆盖池中的
if self.browser and self.browser.is_connected():
self.log("使用池中浏览器,直接登录")
result = self.login(username, password, remember)
if result.get('success'):
self.save_cookies(username)
result['used_cookies'] = False
return result
# 无现有浏览器时尝试使用cookies
if self.load_cookies(username):
self.log(f"尝试使用已保存的登录态...")
if self.check_login_state():
self.log(f"✓ 登录态有效,跳过登录")
return {"success": True, "message": "使用已保存的登录态", "used_cookies": True}
else:
self.log(f"登录态已失效,重新登录")
# <20><>闭当前context重新登录
try:
if self.context:
self.context.close()
if self.browser:
self.browser.close()
if self.playwright:
self.playwright.stop()
except:
pass
# 正常登录
result = self.login(username, password, remember)
# 登录成功后保存cookies
if result.get('success'):
self.save_cookies(username)
result['used_cookies'] = False
return result'''
if old_quick_login in content:
content = content.replace(old_quick_login, new_quick_login)
print("OK - quick_login已修复")
else:
print("WARNING - 未找到old_quick_login")
with open('/www/wwwroot/zsglpt/playwright_automation.py', 'w', encoding='utf-8') as f:
f.write(content)
print("完成")