fix:修复重连状态与认证流程关键缺陷
This commit is contained in:
@@ -102,6 +102,7 @@ var _game_token: String = "" # @deprecated 使用 _access_token 替代
|
||||
# 初始化管理器
|
||||
func _init() -> void:
|
||||
_load_auth_data()
|
||||
_connect_network_signals()
|
||||
|
||||
# 清理资源
|
||||
func cleanup() -> void:
|
||||
@@ -110,6 +111,8 @@ func cleanup() -> void:
|
||||
NetworkManager.cancel_request(request_id)
|
||||
active_request_ids.clear()
|
||||
|
||||
_disconnect_network_signals()
|
||||
|
||||
# ============ Token 管理 ============
|
||||
|
||||
# 保存 Token 到内存
|
||||
@@ -675,7 +678,7 @@ func _on_send_login_code_response(success: bool, data: Dictionary, error_info: D
|
||||
func _on_forgot_password_response(success: bool, data: Dictionary, error_info: Dictionary):
|
||||
button_state_changed.emit("forgot_password_btn", false, "忘记密码")
|
||||
|
||||
var result = ResponseHandler.handle_send_login_code_response(success, data, error_info)
|
||||
var result = ResponseHandler.handle_forgot_password_response(success, data, error_info)
|
||||
|
||||
if result.should_show_toast:
|
||||
show_toast_message.emit(result.message, result.success)
|
||||
@@ -714,10 +717,10 @@ func _can_send_verification_code(email: String) -> bool:
|
||||
if not email_data.sent:
|
||||
return true
|
||||
|
||||
var current_time = Time.get_time_dict_from_system()
|
||||
var current_timestamp = current_time.hour * 3600 + current_time.minute * 60 + current_time.second
|
||||
var current_timestamp: int = int(Time.get_unix_time_from_system())
|
||||
var sent_timestamp: int = int(email_data.get("time", 0))
|
||||
|
||||
return (current_timestamp - email_data.time) >= code_cooldown
|
||||
return float(current_timestamp - sent_timestamp) >= code_cooldown
|
||||
|
||||
# 获取剩余冷却时间
|
||||
func get_remaining_cooldown_time(email: String) -> int:
|
||||
@@ -725,15 +728,15 @@ func get_remaining_cooldown_time(email: String) -> int:
|
||||
return 0
|
||||
|
||||
var email_data = verification_codes_sent[email]
|
||||
var current_time = Time.get_time_dict_from_system()
|
||||
var current_timestamp = current_time.hour * 3600 + current_time.minute * 60 + current_time.second
|
||||
var current_timestamp: int = int(Time.get_unix_time_from_system())
|
||||
var sent_timestamp: int = int(email_data.get("time", 0))
|
||||
var remaining: int = int(code_cooldown - float(current_timestamp - sent_timestamp))
|
||||
|
||||
return int(code_cooldown - (current_timestamp - email_data.time))
|
||||
return maxi(0, remaining)
|
||||
|
||||
# 记录验证码发送状态
|
||||
func _record_verification_code_sent(email: String):
|
||||
var current_time = Time.get_time_dict_from_system()
|
||||
var current_timestamp = current_time.hour * 3600 + current_time.minute * 60 + current_time.second
|
||||
var current_timestamp: int = int(Time.get_unix_time_from_system())
|
||||
|
||||
if not verification_codes_sent.has(email):
|
||||
verification_codes_sent[email] = {}
|
||||
@@ -758,6 +761,30 @@ func _has_sent_verification_code(email: String) -> bool:
|
||||
func _is_valid_identifier(identifier: String) -> bool:
|
||||
return StringUtils.is_valid_email(identifier) or _is_valid_phone(identifier)
|
||||
|
||||
# 连接/断开 NetworkManager 请求信号,用于回收 active_request_ids
|
||||
func _connect_network_signals() -> void:
|
||||
if not NetworkManager.request_completed.is_connected(_on_network_request_completed):
|
||||
NetworkManager.request_completed.connect(_on_network_request_completed)
|
||||
if not NetworkManager.request_failed.is_connected(_on_network_request_failed):
|
||||
NetworkManager.request_failed.connect(_on_network_request_failed)
|
||||
|
||||
func _disconnect_network_signals() -> void:
|
||||
if NetworkManager.request_completed.is_connected(_on_network_request_completed):
|
||||
NetworkManager.request_completed.disconnect(_on_network_request_completed)
|
||||
if NetworkManager.request_failed.is_connected(_on_network_request_failed):
|
||||
NetworkManager.request_failed.disconnect(_on_network_request_failed)
|
||||
|
||||
func _on_network_request_completed(request_id: String, _success: bool, _data: Dictionary) -> void:
|
||||
_remove_active_request_id(request_id)
|
||||
|
||||
func _on_network_request_failed(request_id: String, _error_type: String, _message: String) -> void:
|
||||
_remove_active_request_id(request_id)
|
||||
|
||||
func _remove_active_request_id(request_id: String) -> void:
|
||||
var index: int = active_request_ids.find(request_id)
|
||||
if index != -1:
|
||||
active_request_ids.remove_at(index)
|
||||
|
||||
# 验证手机号格式
|
||||
func _is_valid_phone(phone: String) -> bool:
|
||||
var regex = RegEx.new()
|
||||
|
||||
Reference in New Issue
Block a user