chore: 更好的 SSO 登录

This commit is contained in:
Chenx Dust
2026-01-31 03:45:36 +08:00
parent b5992642a2
commit a922b3bd7e
5 changed files with 37 additions and 1 deletions

View File

@@ -32,6 +32,14 @@ void SsoLoginWebView::setupConnections()
connect(ui->backButton, &QToolButton::clicked, ui->webEngineView, &QWebEngineView::back);
connect(ui->forwardButton, &QToolButton::clicked, ui->webEngineView, &QWebEngineView::forward);
connect(ui->reloadButton, &QToolButton::clicked, ui->webEngineView, &QWebEngineView::reload);
connect(ui->dialogButtonBox, &QDialogButtonBox::rejected, this, [&]()
{
if (!loginCompletedEmitted)
{
loginCompletedEmitted = true;
loginCompleted(QString());
}
});
connect(ui->addressLineEdit, &QLineEdit::returnPressed, this, [&]()
{
@@ -49,7 +57,11 @@ void SsoLoginWebView::setupConnections()
if (request.navigationType() == QWebEngineNavigationRequest::NavigationType::RedirectNavigation &&
request.url().host() == callbackServerHost)
{
loginCompleted(request.url().toString());
if (!loginCompletedEmitted)
{
loginCompletedEmitted = true;
loginCompleted(request.url().toString());
}
request.reject();
this->close();
}
@@ -76,3 +88,14 @@ QUrl SsoLoginWebView::currentUrl() const
{
return ui->webEngineView->url();
}
void SsoLoginWebView::closeEvent(QCloseEvent *event)
{
if (!loginCompletedEmitted)
{
loginCompletedEmitted = true;
loginCompleted(QString());
}
QDialog::closeEvent(event);
}

View File

@@ -4,6 +4,7 @@
#include <QDialog>
#include <QUrl>
#include <QString>
#include <QCloseEvent>
namespace Ui
{
@@ -25,11 +26,15 @@ public:
signals:
void loginCompleted(const QString &url);
protected:
void closeEvent(QCloseEvent *event) override;
private:
void setupConnections();
Ui::SsoLoginWebView *ui;
QString callbackServerHost;
bool loginCompletedEmitted = false;
};
#endif // SSOLOGINWEBVIEW_H

View File

@@ -70,6 +70,10 @@ ZjuConnectController::ZjuConnectController(QWidget* parent) : QObject(parent)
{
emit error(ZJU_ERROR::OTHER_LOGIN_FAILED);
}
else if (output.contains("unexpected newline"))
{
emit error(ZJU_ERROR::INTERACTIVE_ERROR);
}
else if (output.contains("client setup error"))
{
emit error(ZJU_ERROR::CLIENT_FAILED);

View File

@@ -14,6 +14,7 @@ enum class ZJU_ERROR
CLIENT_FAILED,
CAPTCHA_FAILED,
PROGRAM_NOT_FOUND,
INTERACTIVE_ERROR,
OTHER,
};

View File

@@ -133,6 +133,9 @@ void MainWindow::initZjuConnect()
case ZJU_ERROR::PROGRAM_NOT_FOUND:
QMessageBox::critical(this, "错误", "程序未找到!\n请检查核心是否在正确路径下,检查是否解压在当前目录下。");
break;
case ZJU_ERROR::INTERACTIVE_ERROR:
QMessageBox::critical(this, "错误", "登录失败!\n请检查您的输入是否正确,检查是否完成 SSO 登录。");
break;
case ZJU_ERROR::OTHER:
QMessageBox::critical(this, "错误", "其它错误!\n未知原因,可将日志反馈给开发者以便调查。");
break;