fix: free resources in slots

This commit is contained in:
Kevin Yue 2022-05-22 23:17:11 +08:00
parent dffbc64ef5
commit 8fe717d844
4 changed files with 40 additions and 9 deletions

View File

@ -162,9 +162,18 @@ void GatewayAuthenticator::samlAuth(QString samlMethod, QString samlRequest, QSt
SAMLLoginWindow *loginWindow = new SAMLLoginWindow; SAMLLoginWindow *loginWindow = new SAMLLoginWindow;
connect(loginWindow, &SAMLLoginWindow::success, this, &GatewayAuthenticator::onSAMLLoginSuccess); connect(loginWindow, &SAMLLoginWindow::success, [this, loginWindow](const QMap<QString, QString> &samlResult) {
connect(loginWindow, &SAMLLoginWindow::fail, this, &GatewayAuthenticator::onSAMLLoginFail); this->onSAMLLoginSuccess(samlResult);
connect(loginWindow, &SAMLLoginWindow::rejected, this, &GatewayAuthenticator::onLoginWindowRejected); loginWindow->deleteLater();
});
connect(loginWindow, &SAMLLoginWindow::fail, [this, loginWindow](const QString &error) {
this->onSAMLLoginFail(error);
loginWindow->deleteLater();
});
connect(loginWindow, &SAMLLoginWindow::rejected, [this, loginWindow]() {
this->onLoginWindowRejected();
loginWindow->deleteLater();
});
loginWindow->login(samlMethod, samlRequest, preloginUrl); loginWindow->login(samlMethod, samlRequest, preloginUrl);
} }

View File

@ -279,12 +279,24 @@ void GPClient::portalLogin()
{ {
PortalAuthenticator *portalAuth = new PortalAuthenticator(portal(), settings::get("clientos", "Linux").toString()); PortalAuthenticator *portalAuth = new PortalAuthenticator(portal(), settings::get("clientos", "Linux").toString());
connect(portalAuth, &PortalAuthenticator::success, this, &GPClient::onPortalSuccess); connect(portalAuth, &PortalAuthenticator::success, [this, portalAuth](const PortalConfigResponse response, const QString region) {
this->onPortalSuccess(response, region);
portalAuth->deleteLater();
});
// Prelogin failed on the portal interface, try to treat the portal as a gateway interface // Prelogin failed on the portal interface, try to treat the portal as a gateway interface
connect(portalAuth, &PortalAuthenticator::preloginFailed, this, &GPClient::onPortalPreloginFail); connect(portalAuth, &PortalAuthenticator::preloginFailed, [this, portalAuth](const QString msg) {
connect(portalAuth, &PortalAuthenticator::portalConfigFailed, this, &GPClient::onPortalConfigFail); this->onPortalPreloginFail(msg);
portalAuth->deleteLater();
});
connect(portalAuth, &PortalAuthenticator::portalConfigFailed, [this, portalAuth](const QString msg) {
this->onPortalConfigFail(msg);
portalAuth->deleteLater();
});
// Portal login failed // Portal login failed
connect(portalAuth, &PortalAuthenticator::fail, this, &GPClient::onPortalFail); connect(portalAuth, &PortalAuthenticator::fail, [this, portalAuth](const QString &msg) {
this->onPortalFail(msg);
portalAuth->deleteLater();
});
ui->statusLabel->setText("Authenticating..."); ui->statusLabel->setText("Authenticating...");
updateConnectionStatus(VpnStatus::pending); updateConnectionStatus(VpnStatus::pending);
@ -359,8 +371,14 @@ void GPClient::gatewayLogin()
GatewayAuthenticator *gatewayAuth = new GatewayAuthenticator(currentGateway().address(), params); GatewayAuthenticator *gatewayAuth = new GatewayAuthenticator(currentGateway().address(), params);
connect(gatewayAuth, &GatewayAuthenticator::success, this, &GPClient::onGatewaySuccess); connect(gatewayAuth, &GatewayAuthenticator::success, [this, gatewayAuth](const QString &authToken) {
connect(gatewayAuth, &GatewayAuthenticator::fail, this, &GPClient::onGatewayFail); this->onGatewaySuccess(authToken);
gatewayAuth->deleteLater();
});
connect(gatewayAuth, &GatewayAuthenticator::fail, [this, gatewayAuth](const QString &msg) {
this->onGatewayFail(msg);
gatewayAuth->deleteLater();
});
ui->statusLabel->setText("Authenticating..."); ui->statusLabel->setText("Authenticating...");
updateConnectionStatus(VpnStatus::pending); updateConnectionStatus(VpnStatus::pending);

View File

@ -9,6 +9,7 @@
#include "portalconfigresponse.h" #include "portalconfigresponse.h"
#include "settingsdialog.h" #include "settingsdialog.h"
#include "vpn.h" #include "vpn.h"
#include "gatewayauthenticator.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class GPClient; } namespace Ui { class GPClient; }
@ -80,6 +81,8 @@ private:
SettingsDialog *settingsDialog; SettingsDialog *settingsDialog;
QPushButton *settingsButton; QPushButton *settingsButton;
GatewayAuthenticator *gatewayAuthenticator;
bool isQuickConnect { false }; bool isQuickConnect { false };
bool isSwitchingGateway { false }; bool isSwitchingGateway { false };
PortalConfigResponse portalConfig; PortalConfigResponse portalConfig;

View File

@ -15,6 +15,7 @@ SAMLLoginWindow::SAMLLoginWindow(QWidget *parent)
QVBoxLayout *verticalLayout = new QVBoxLayout(this); QVBoxLayout *verticalLayout = new QVBoxLayout(this);
webView->setUrl(QUrl("about:blank")); webView->setUrl(QUrl("about:blank"));
webView->setAttribute(Qt::WA_DeleteOnClose);
// webView->page()->profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); // webView->page()->profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
verticalLayout->addWidget(webView); verticalLayout->addWidget(webView);