diff options
Diffstat (limited to 'src/loginform.cpp')
-rw-r--r-- | src/loginform.cpp | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/src/loginform.cpp b/src/loginform.cpp index bb4fdb9..230f408 100644 --- a/src/loginform.cpp +++ b/src/loginform.cpp @@ -17,6 +17,7 @@ #include "global.h" #include "namereplace.h" #include "loginrpc.h" +#include "qrlogin.h" #undef KeyPress #undef KeyRelease #undef FocusIn @@ -44,7 +45,9 @@ LoginForm::LoginForm(QWidget *parent) : browser(nullptr), clearMsg(false), capsOn(-1), - pageCount(0) + pageCount(0), + qrcode(nullptr), + qrlogin(nullptr) { ui->setupUi(this); origSize = shibSize = sizeHint(); @@ -160,6 +163,8 @@ void LoginForm::initialize() // timer to reset the form to its original state if (Settings::resetForm() > 0) { connect(&resetFormTimer, &QTimer::timeout, [this]() { + if (ui->loginChooser->currentWidget() == ui->qrPage) + return; int idleTime = static_cast<int>(getIdleTime(QX11Info::display())); int remaining = Settings::resetForm() * 1000 - idleTime; if (remaining <= 0) { @@ -210,6 +215,18 @@ void LoginForm::initialize() ui->shibButton->hide(); } + if (Settings::qrSessionEnabled()) { + pageCount += 2; // Fake this so we always return on timeout; + // otherwise, the qr code could expire after some time, breaking + // the login process. + if (!Settings::qrSessionButtonText().isEmpty()) { + ui->qrButton->setText(Settings::qrSessionButtonText()); + } + connect(ui->qrButton, &QAbstractButton::released, this, &LoginForm::showQrWindow); + } else { + ui->qrButton->hide(); + } + if (Settings::userSessionEnabled()) { pageCount++; } else { @@ -296,6 +313,31 @@ void LoginForm::showShibWindow() { setBrowserSize(); } +void LoginForm::showQrWindow() { + if (qrcode == nullptr) { + qrcode = new QLabel(this); + ui->vlQrCode->addWidget(qrcode); + qrcode->setBackgroundRole(QPalette::Shadow); + //connect(browser, &WebView::startAuthentication, this, &LoginForm::startAuthAs); + } + if (qrlogin != nullptr) { + disconnect(qrlogin); + qrlogin->deleteLater(); + } + qrlogin = new QrLogin(this); + connect(qrlogin, &QrLogin::startAuthentication, this, &LoginForm::startAuthAs); + connect(qrlogin, &QrLogin::updateStatus, this, &LoginForm::showLowPrioMessage); + connect(qrlogin, &QrLogin::triggerReset, [this](const QString &message) { + this->showMessage(message, true); + ui->loginChooser->setCurrentWidget(ui->welcomePage); + }); + QPixmap pm(20, 20); + pm.fill(Qt::red); + qrcode->setPixmap(pm); + qrlogin->loadQrCode(qrcode); + ui->loginChooser->setCurrentWidget(ui->qrPage); +} + void LoginForm::checkCaps() { unsigned int mask = getKeyMask(QX11Info::display()); @@ -407,6 +449,9 @@ void LoginForm::cancelLogin() std::cerr << "Was in authentication" << std::endl; Global::greeter()->cancelAuthentication(); } + if (ui->loginChooser->currentWidget() != ui->loginPage && pageCount > 1) { + ui->loginChooser->setCurrentWidget(ui->welcomePage); + } cancelLoginTimer.stop(); ui->passwordInput->clear(); enableInputs(true); @@ -425,11 +470,20 @@ void LoginForm::enableInputs(bool enable) ui->passwordInput->setEnabled(enable); ui->backButton->setEnabled(enable); ui->guestButton->setEnabled(enable); + ui->shibButton->setEnabled(enable); + ui->qrButton->setEnabled(enable); if (browser != nullptr) { browser->setEnabled(enable); } } +void LoginForm::showLowPrioMessage(QString message) +{ + if (!ui->messageLabel->text().isEmpty() && !ui->messageLabel->styleSheet().isEmpty()) + return; + showMessage(message, false); +} + void LoginForm::showMessage(QString message, bool error) { hideMessageTimer.stop(); @@ -478,6 +532,10 @@ void LoginForm::keyPressEvent(QKeyEvent *event) void LoginForm::resetForm() { std::cerr << "PageCount: " << pageCount << std::endl; + if (ui->loginChooser->currentWidget() == ui->qrPage && qrlogin != nullptr) { + qrlogin->abort(); + hideMessage(); + } if (pageCount > 1) { ui->loginChooser->setCurrentWidget(ui->welcomePage); } |