chore: use auto to declare variables

This commit is contained in:
Kevin Yue 2022-06-12 16:44:07 +08:00
parent 35266dd8bf
commit 5ebfe9b0f4
3 changed files with 9 additions and 14 deletions

View File

@ -23,11 +23,6 @@ GatewayAuthenticator::GatewayAuthenticator(const QString& gateway, GatewayAuthen
} }
} }
GatewayAuthenticator::~GatewayAuthenticator()
{
delete normalLoginWindow;
}
void GatewayAuthenticator::authenticate() void GatewayAuthenticator::authenticate()
{ {
LOGI << "Start gateway authentication..."; LOGI << "Start gateway authentication...";
@ -43,9 +38,9 @@ void GatewayAuthenticator::authenticate()
void GatewayAuthenticator::login(const LoginParams &loginParams) void GatewayAuthenticator::login(const LoginParams &loginParams)
{ {
LOGI << "Trying to login the gateway at " << loginUrl << " with " << loginParams.toUtf8(); LOGI << QString("Trying to login the gateway at %1, with %2").arg(loginUrl).arg(QString::fromUtf8(loginParams.toUtf8()));
QNetworkReply *reply = createRequest(loginUrl, loginParams.toUtf8()); auto *reply = createRequest(loginUrl, loginParams.toUtf8());
connect(reply, &QNetworkReply::finished, this, &GatewayAuthenticator::onLoginFinished); connect(reply, &QNetworkReply::finished, this, &GatewayAuthenticator::onLoginFinished);
} }
@ -77,7 +72,7 @@ void GatewayAuthenticator::onLoginFinished()
normalLoginWindow->close(); normalLoginWindow->close();
} }
const QUrlQuery params = gpclient::helper::parseGatewayResponse(response); const auto params = gpclient::helper::parseGatewayResponse(response);
emit success(params.toString()); emit success(params.toString());
} }
@ -85,13 +80,13 @@ void GatewayAuthenticator::doAuth()
{ {
LOGI << "Perform the gateway prelogin at " << preloginUrl; LOGI << "Perform the gateway prelogin at " << preloginUrl;
QNetworkReply *reply = createRequest(preloginUrl); auto *reply = createRequest(preloginUrl);
connect(reply, &QNetworkReply::finished, this, &GatewayAuthenticator::onPreloginFinished); connect(reply, &QNetworkReply::finished, this, &GatewayAuthenticator::onPreloginFinished);
} }
void GatewayAuthenticator::onPreloginFinished() void GatewayAuthenticator::onPreloginFinished()
{ {
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); auto *reply = qobject_cast<QNetworkReply*>(sender());
if (reply->error()) { if (reply->error()) {
LOGE << QString("Failed to prelogin the gateway at %1, %2").arg(preloginUrl, reply->errorString()); LOGE << QString("Failed to prelogin the gateway at %1, %2").arg(preloginUrl, reply->errorString());
@ -102,7 +97,7 @@ void GatewayAuthenticator::onPreloginFinished()
LOGI << "Gateway prelogin succeeded."; LOGI << "Gateway prelogin succeeded.";
PreloginResponse response = PreloginResponse::parse(reply->readAll()); auto response = PreloginResponse::parse(reply->readAll());
if (response.hasSamlAuthFields()) { if (response.hasSamlAuthFields()) {
samlAuth(response.samlMethod(), response.samlRequest(), reply->url().toString()); samlAuth(response.samlMethod(), response.samlRequest(), reply->url().toString());

View File

@ -12,8 +12,7 @@ class GatewayAuthenticator : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GatewayAuthenticator(const QString& gateway, GatewayAuthenticatorParams params); explicit GatewayAuthenticator(const QString &gateway, GatewayAuthenticatorParams params);
~GatewayAuthenticator();
void authenticate(); void authenticate();

View File

@ -369,7 +369,8 @@ void GPClient::gatewayLogin()
GatewayAuthenticatorParams params = GatewayAuthenticatorParams::fromPortalConfigResponse(portalConfig); GatewayAuthenticatorParams params = GatewayAuthenticatorParams::fromPortalConfigResponse(portalConfig);
params.setClientos(settings::get("clientos", "Linux").toString()); params.setClientos(settings::get("clientos", "Linux").toString());
GatewayAuthenticator *gatewayAuth = new GatewayAuthenticator(currentGateway().address(), params); GatewayAuthenticator *gatewayAuth;
gatewayAuth = new GatewayAuthenticator(currentGateway().address(), params);
connect(gatewayAuth, &GatewayAuthenticator::success, [this, gatewayAuth](const QString &authToken) { connect(gatewayAuth, &GatewayAuthenticator::success, [this, gatewayAuth](const QString &authToken) {
this->onGatewaySuccess(authToken); this->onGatewaySuccess(authToken);