mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-08-26 13:29:31 +08:00
[fix] recover interrupted password changes
This commit is contained in:
@@ -61,6 +61,40 @@ int GuiRuntime::CreateConnectionPeer() {
|
||||
params_.user_id = client_id_with_password_;
|
||||
}
|
||||
|
||||
const bool self_hosted = config_center_->IsSelfHosted();
|
||||
const std::string pending_identity =
|
||||
settings_.PendingPasswordChangeIdentity(
|
||||
self_hosted, signal_server_ip, signal_server_port);
|
||||
bool try_pending_identity = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(password_change_mutex_);
|
||||
if (pending_identity.empty()) {
|
||||
credential_recovery_in_progress_ = false;
|
||||
credential_recovery_attempt_pending_ = false;
|
||||
credential_recovery_retry_active_ = false;
|
||||
credential_recovery_promote_pending_ = false;
|
||||
credential_recovery_clear_pending_ = false;
|
||||
} else if (!credential_recovery_in_progress_) {
|
||||
credential_recovery_in_progress_ = true;
|
||||
credential_recovery_attempt_pending_ = true;
|
||||
LOG_INFO("Recovering an interrupted password change for [{}]",
|
||||
client_id_);
|
||||
}
|
||||
try_pending_identity = credential_recovery_in_progress_ &&
|
||||
credential_recovery_attempt_pending_ &&
|
||||
!pending_identity.empty();
|
||||
}
|
||||
|
||||
const char *active_identity =
|
||||
self_hosted ? self_hosted_user_id_ : client_id_with_password_;
|
||||
const std::string login_identity =
|
||||
try_pending_identity ? pending_identity : std::string(active_identity);
|
||||
std::memset(connection_login_identity_, 0,
|
||||
sizeof(connection_login_identity_));
|
||||
std::strncpy(connection_login_identity_, login_identity.c_str(),
|
||||
sizeof(connection_login_identity_) - 1);
|
||||
params_.user_id = connection_login_identity_;
|
||||
|
||||
// self hosted server config
|
||||
strncpy(signal_server_ip_self_, config_center_->GetSignalServerHost().c_str(),
|
||||
sizeof(signal_server_ip_self_) - 1);
|
||||
|
||||
@@ -116,6 +116,7 @@ void PeerEventHandler::OnSignalMessage(const char* message, size_t size,
|
||||
j.contains("reason") && j["reason"].is_string()
|
||||
? j["reason"].get<std::string>()
|
||||
: "Password change failed";
|
||||
runtime->password_change_result_uncertain_ = false;
|
||||
runtime->password_change_result_ready_ = true;
|
||||
}
|
||||
}
|
||||
@@ -137,8 +138,21 @@ void PeerEventHandler::OnSignalStatus(SignalStatus status, const char* user_id,
|
||||
runtime->signal_connected_ = true;
|
||||
runtime->need_to_send_recent_connections_ = true;
|
||||
LOG_INFO("[{}] connected to signal server", client_id);
|
||||
std::lock_guard<std::mutex> lock(runtime->password_change_mutex_);
|
||||
if (runtime->credential_recovery_in_progress_) {
|
||||
if (runtime->credential_recovery_attempt_pending_) {
|
||||
runtime->credential_recovery_promote_pending_ = true;
|
||||
} else {
|
||||
runtime->credential_recovery_clear_pending_ = true;
|
||||
}
|
||||
}
|
||||
} else if (SignalStatus::SignalFailed == status) {
|
||||
runtime->signal_connected_ = false;
|
||||
std::lock_guard<std::mutex> lock(runtime->password_change_mutex_);
|
||||
if (runtime->credential_recovery_in_progress_ &&
|
||||
runtime->credential_recovery_attempt_pending_) {
|
||||
runtime->credential_recovery_retry_active_ = true;
|
||||
}
|
||||
} else if (SignalStatus::SignalClosed == status) {
|
||||
runtime->signal_connected_ = false;
|
||||
} else if (SignalStatus::SignalReconnecting == status) {
|
||||
|
||||
@@ -116,6 +116,7 @@ struct UserSettingsState {
|
||||
char password_saved_[7] = "";
|
||||
char self_hosted_id_[17] = "";
|
||||
char self_hosted_user_id_[17] = "";
|
||||
char connection_login_identity_[17] = "";
|
||||
int language_button_value_ = 0;
|
||||
int video_quality_button_value_ = 2;
|
||||
int video_frame_rate_button_value_ = 1;
|
||||
@@ -158,10 +159,16 @@ struct PasswordChangeState {
|
||||
bool password_change_pending_ = false;
|
||||
bool password_change_result_ready_ = false;
|
||||
bool password_change_succeeded_ = false;
|
||||
bool password_change_result_uncertain_ = false;
|
||||
std::chrono::steady_clock::time_point password_change_requested_at_;
|
||||
std::string pending_password_change_request_id_;
|
||||
std::string pending_local_password_;
|
||||
std::string password_change_error_;
|
||||
bool credential_recovery_in_progress_ = false;
|
||||
bool credential_recovery_attempt_pending_ = false;
|
||||
bool credential_recovery_retry_active_ = false;
|
||||
bool credential_recovery_promote_pending_ = false;
|
||||
bool credential_recovery_clear_pending_ = false;
|
||||
};
|
||||
|
||||
struct ConnectionState {
|
||||
|
||||
Reference in New Issue
Block a user