Improve the authentication workflow (#18)

This commit is contained in:
Kevin Yue 2020-05-31 12:14:56 +08:00 committed by GitHub
parent 3a790cdc63
commit cf34f9f70f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 22 deletions

View File

@ -243,6 +243,7 @@ void GPClient::portalLogin()
connect(portalAuth, &PortalAuthenticator::success, this, &GPClient::onPortalSuccess);
// 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::portalConfigFailed, this, &GPClient::onPortalConfigFail);
// Portal login failed
connect(portalAuth, &PortalAuthenticator::fail, this, &GPClient::onPortalFail);
@ -251,21 +252,49 @@ void GPClient::portalLogin()
portalAuth->authenticate();
}
void GPClient::onPortalSuccess(const PortalConfigResponse portalConfig, const GPGateway gateway, QList<GPGateway> allGateways)
void GPClient::onPortalSuccess(const PortalConfigResponse portalConfig, const QString region)
{
PLOGI << "Portal authentication succeeded.";
this->portalConfig = portalConfig;
// No gateway found in protal configuration
if (portalConfig.allGateways().size() == 0) {
PLOGI << "No gateway found in portal configuration, treat the portal address as a gateway.";
tryGatewayLogin();
return;
}
setAllGateways(allGateways);
GPGateway gateway = filterPreferredGateway(portalConfig.allGateways(), region);
setAllGateways(portalConfig.allGateways());
setCurrentGateway(gateway);
this->portalConfig = portalConfig;
gatewayLogin();
}
void GPClient::onPortalPreloginFail()
void GPClient::onPortalPreloginFail(const QString msg)
{
PLOGI << "Portal prelogin failed, try to preform login on the the gateway interface...";
PLOGI << "Portal prelogin failed: " << msg;
tryGatewayLogin();
}
void GPClient::onPortalConfigFail(const QString msg)
{
PLOGI << "Failed to get the portal configuration, " << msg << " Treat the portal address as gateway.";
tryGatewayLogin();
}
void GPClient::onPortalFail(const QString &msg)
{
if (!msg.isEmpty()) {
openMessageBox("Portal authentication failed.", msg);
}
updateConnectionStatus(VpnStatus::disconnected);
}
void GPClient::tryGatewayLogin()
{
PLOGI << "Try to preform login on the the gateway interface...";
// Treat the portal input as the gateway address
GPGateway g;
@ -281,15 +310,6 @@ void GPClient::onPortalPreloginFail()
gatewayLogin();
}
void GPClient::onPortalFail(const QString &msg)
{
if (!msg.isEmpty()) {
openMessageBox("Portal authentication failed.", msg);
}
updateConnectionStatus(VpnStatus::disconnected);
}
// Login to the gateway
void GPClient::gatewayLogin()
{

View File

@ -30,8 +30,9 @@ private slots:
void onSystemTrayActivated(QSystemTrayIcon::ActivationReason reason);
void onGatewayChanged(QAction *action);
void onPortalSuccess(const PortalConfigResponse portalConfig, const GPGateway gateway, QList<GPGateway> allGateways);
void onPortalPreloginFail();
void onPortalSuccess(const PortalConfigResponse portalConfig, const QString region);
void onPortalPreloginFail(const QString msg);
void onPortalConfigFail(const QString msg);
void onPortalFail(const QString &msg);
void onGatewaySuccess(const QString &authCookie);
@ -72,6 +73,7 @@ private:
void doConnect();
void portalLogin();
void tryGatewayLogin();
void gatewayLogin();
QString portal() const;

View File

@ -57,7 +57,7 @@ void PortalAuthenticator::onPreloginFinished()
tryAutoLogin();
} else {
PLOGE << QString("Unknown prelogin response for %1 got %2").arg(preloginUrl).arg(QString::fromUtf8(preloginResponse.rawResponse()));
emitFail("Unknown response for portal prelogin interface.");
emit preloginFailed("Unknown response for portal prelogin interface.");
}
delete reply;
@ -175,7 +175,7 @@ void PortalAuthenticator::onFetchConfigFinished()
isAutoLogin = false;
normalAuth();
} else {
emitFail("Failed to fetch the portal config.");
emit portalConfigFailed("Failed to fetch the portal config.");
}
return;
}
@ -197,7 +197,7 @@ void PortalAuthenticator::onFetchConfigFinished()
normalLoginWindow->close();
}
emit success(response, filterPreferredGateway(response.allGateways(), preloginResponse.region()), response.allGateways());
emit success(response, preloginResponse.region());
}
void PortalAuthenticator::emitFail(const QString& msg)

View File

@ -18,9 +18,10 @@ public:
void authenticate();
signals:
void success(const PortalConfigResponse, const GPGateway, QList<GPGateway> allGateways);
void success(const PortalConfigResponse response, const QString region);
void fail(const QString& msg);
void preloginFailed(const QString& msg);
void portalConfigFailed(const QString msg);
private slots:
void onPreloginFinished();

View File

@ -132,7 +132,7 @@ QString PortalConfigResponse::prelogonUserAuthCookie() const
return _prelogonAuthCookie;
}
QList<GPGateway> PortalConfigResponse::allGateways()
QList<GPGateway> PortalConfigResponse::allGateways() const
{
return _gateways;
}

View File

@ -20,7 +20,7 @@ public:
QString password() const;
QString userAuthCookie() const;
QString prelogonUserAuthCookie() const;
QList<GPGateway> allGateways();
QList<GPGateway> allGateways() const;
void setAllGateways(QList<GPGateway> gateways);
void setUsername(const QString username);