summaryrefslogtreecommitdiffstats
path: root/src/loginform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/loginform.cpp')
-rw-r--r--src/loginform.cpp168
1 files changed, 142 insertions, 26 deletions
diff --git a/src/loginform.cpp b/src/loginform.cpp
index a53c7ab..eecf34b 100644
--- a/src/loginform.cpp
+++ b/src/loginform.cpp
@@ -8,13 +8,15 @@
* Please refer to the LICENSE file for a copy of the license.
*/
+#include <QTextStream>
+
+#include "x11util.h"
#include "loginform.h"
#include "ui_loginform.h"
#include "settings.h"
#include "global.h"
#include "namereplace.h"
#include "loginrpc.h"
-#include "x11util.h"
#undef KeyPress
#undef KeyRelease
#undef FocusIn
@@ -29,6 +31,9 @@
#include <QListView>
#include <QSvgRenderer>
#include <QX11Info>
+#include "webview.h"
+#include <QSizePolicy>
+
#include <iostream>
void createSimpleBackground();
@@ -36,10 +41,19 @@ void createSimpleBackground();
LoginForm::LoginForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::LoginForm),
+ browser(nullptr),
clearMsg(false),
capsOn(-1)
{
ui->setupUi(this);
+ origSize = shibSize = sizeHint();
+ if (this->parentWidget() != nullptr) {
+ shibSize.setWidth(qMin(1000, int(this->parentWidget()->width() * .75f) ));
+ shibSize.setHeight(qMin(700, int(this->parentWidget()->height() * .75f) ));
+ } else {
+ shibSize.rwidth() += 350;
+ shibSize.rheight() += 250;
+ }
initialize();
int port = Settings::rpcPort();
if (port != 0) {
@@ -49,14 +63,14 @@ LoginForm::LoginForm(QWidget *parent) :
return;
ui->userInput->setText(username);
ui->passwordInput->setText(password);
- this->startAuthentication();
+ this->startFormBasedAuthentication();
});
}
+ connect(ui->loginChooser, &QStackedWidget::currentChanged, this, &LoginForm::setBrowserSize);
}
LoginForm::~LoginForm()
{
-
delete ui;
}
@@ -69,14 +83,45 @@ void LoginForm::setFocus(Qt::FocusReason reason)
}
}
+void LoginForm::resizeEvent(QResizeEvent *e)
+{
+ if (this->parentWidget() != nullptr) {
+ shibSize.setWidth(qMin(1000, int(this->parentWidget()->width() * .75f) ));
+ shibSize.setHeight(qMin(700, int(this->parentWidget()->height() * .75f) ));
+ }
+ const QSize *size = nullptr;
+ if (ui->loginChooser->currentWidget() == ui->shibPage) {
+ size = &shibSize;
+ } else {
+ size = &origSize;
+ }
+ if (*size != e->size()) {
+ e->ignore();
+ setMinimumSize(*size);
+ setFixedSize(*size);
+ setBaseSize(*size);
+ int pw = 0, ph = 0;
+ if (this->parentWidget() != nullptr) {
+ this->parentWidget()->pos();
+ pw = (this->parentWidget()->width() - size->width()) / 2;
+ ph = (this->parentWidget()->height() - size->height()) / 2;
+ }
+ setGeometry(pw, pw, size->width(), size->height());
+ emit resized();
+ setBrowserSize();
+ return;
+ }
+ QWidget::resizeEvent(e);
+}
void LoginForm::initialize()
{
QString path = Settings::miniIconFile();
QPixmap pixmap;
if (!path.isEmpty()) {
+ // Try to get the default size, in case this is an SVG
QSize size = QSvgRenderer(path).defaultSize();
- if (!size.isValid()) {
+ if (!size.isValid()) { // if not, use maximum of destination
size = ui->iconLabel->maximumSize();
} else {
size = size.boundedTo(ui->iconLabel->maximumSize()).expandedTo(ui->iconLabel->minimumSize());
@@ -132,13 +177,38 @@ void LoginForm::initialize()
if (!Settings::guestSessionStartButtonText().isEmpty()) {
ui->guestStartButton->setText(Settings::guestSessionStartButtonText());
}
- connect(ui->loginButton, &QAbstractButton::released, this, [this]() {
- ui->loginChooser->setCurrentWidget(ui->loginPage);
- ui->userInput->setFocus();
- });
connect(ui->guestButton, &QAbstractButton::released, this, [this]() {
ui->loginChooser->setCurrentWidget(ui->guestPage);
});
+ } else {
+ ui->guestButton->hide();
+ }
+
+ if (Settings::shibSessionEnabled()) {
+ connect(ui->shibButton, &QAbstractButton::released, this, [this]() {
+ if (browser == nullptr) {
+ browser = new WebView(ui->shibPage);
+ ui->verticalLayout_5->addWidget(browser);
+ connect(browser, &WebView::triggerReset, [this](const QString &message) {
+ this->showMessage(message, true);
+ ui->loginChooser->setCurrentWidget(ui->welcomePage);
+ });
+ connect(browser, &WebView::startAuthentication, this, &LoginForm::startAuthAs);
+ }
+ browser->reset(Settings::shibUrl());
+ ui->loginChooser->setCurrentWidget(ui->shibPage);
+ });
+ // Reduce minimum size of hostname/icon bar
+ ui->frame->setMinimumSize(10, 30);
+ ui->frame->setMaximumSize(99999, ui->iconLabel->height());
+ ui->frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
+ ui->loginChooser->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
+ } else {
+ ui->shibButton->hide();
+ }
+
+ if (Settings::guestSessionEnabled() || Settings::shibSessionEnabled()) {
+ ui->loginChooser->setCurrentWidget(ui->welcomePage);
connect(ui->backButton, &QAbstractButton::released, this, [this]() {
resetForm();
});
@@ -149,7 +219,10 @@ void LoginForm::initialize()
ui->backButton->show();
}
});
- ui->loginChooser->setCurrentWidget(ui->welcomePage);
+ connect(ui->loginButton, &QAbstractButton::released, this, [this]() {
+ ui->loginChooser->setCurrentWidget(ui->loginPage);
+ ui->userInput->setFocus();
+ });
} else {
ui->loginChooser->setCurrentWidget(ui->loginPage);
}
@@ -208,19 +281,12 @@ void LoginForm::checkCaps()
}
}
-void LoginForm::startAuthentication()
+void LoginForm::startFormBasedAuthentication()
{
QString username(ui->userInput->text().trimmed());
NameReplace::replace(username);
std::cerr << "Logging in as " << username.toStdString() << std::endl;
- if (Global::testMode()) {
- showMessage(QLatin1String("Test mode..."), true);
- return;
- }
- if (Global::greeter()->inAuthentication()) {
- Global::greeter()->cancelAuthentication();
- }
if (ui->userInput->text().isEmpty()) {
ui->userInput->setFocus();
return;
@@ -229,20 +295,34 @@ void LoginForm::startAuthentication()
ui->passwordInput->setFocus();
return;
}
+ startAuthAs(username, ui->passwordInput->text());
+ ui->passwordInput->setText("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+ ui->passwordInput->clear();
+}
+void LoginForm::startAuthAs(const QString &user, const QString &pass)
+{
+ if (Global::testMode()) {
+ showMessage(QLatin1String("Test mode..."), true);
+ return;
+ }
+ if (Global::greeter()->inAuthentication()) {
+ Global::greeter()->cancelAuthentication();
+ }
showMessage(tr("Logging in..."), false);
clearMsg = false;
- ui->userInput->setEnabled(false);
- ui->passwordInput->setEnabled(false);
+ enableInputs(false);
cancelLoginTimer.start();
- Global::greeter()->authenticate(username);
+ password = pass;
+ Global::greeter()->authenticate(user);
}
void LoginForm::onPrompt(QString prompt, QLightDM::Greeter::PromptType /* promptType */)
{
std::cerr << "Prompt: " << prompt.toStdString() << std::endl;
- Global::greeter()->respond(ui->passwordInput->text());
- ui->passwordInput->clear();
+ Global::greeter()->respond(password);
+ password = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
+ password.clear();
}
void LoginForm::leaveDropDownActivated(int index)
@@ -298,8 +378,7 @@ void LoginForm::cancelLogin()
}
cancelLoginTimer.stop();
ui->passwordInput->clear();
- ui->userInput->setEnabled(true);
- ui->passwordInput->setEnabled(true);
+ enableInputs(true);
if (!clearMsg) {
showMessage(tr("Login failed"), true);
} else {
@@ -309,6 +388,17 @@ void LoginForm::cancelLogin()
clearMsg = true;
}
+void LoginForm::enableInputs(bool enable)
+{
+ ui->userInput->setEnabled(enable);
+ ui->passwordInput->setEnabled(enable);
+ ui->backButton->setEnabled(enable);
+ ui->guestButton->setEnabled(enable);
+ if (browser != nullptr) {
+ browser->setEnabled(enable);
+ }
+}
+
void LoginForm::showMessage(QString message, bool error)
{
hideMessageTimer.stop();
@@ -343,7 +433,7 @@ void LoginForm::keyPressEvent(QKeyEvent *event)
return;
}
if (ui->passwordInput->hasFocus()) {
- startAuthentication();
+ startFormBasedAuthentication();
return;
}
}
@@ -356,8 +446,9 @@ void LoginForm::keyPressEvent(QKeyEvent *event)
void LoginForm::resetForm()
{
- if (Settings::guestSessionEnabled())
+ if (Settings::guestSessionEnabled() || Settings::shibSessionEnabled()) {
ui->loginChooser->setCurrentWidget(ui->welcomePage);
+ }
ui->passwordInput->clear();
ui->userInput->clear();
ui->userInput->setFocus();
@@ -370,3 +461,28 @@ bool LoginForm::eventFilter(QObject *object, QEvent *event)
}
return false;
}
+
+void LoginForm::setBrowserSize()
+{
+ auto s = ui->shibPage->size();
+ auto *f = &shibSize;
+ if (ui->loginChooser->currentWidget() != ui->shibPage) {
+ f = &origSize;
+ s = QSize(50, 50);
+ }
+ if (browser != nullptr) {
+ browser->setFixedSize(s);
+ browser->setGeometry(QRect(QPoint(0, 0), s));
+ }
+ QTimer::singleShot(10, [=]() {
+ int pw = 0, ph = 0;
+ if (this->parentWidget() != nullptr) {
+ this->parentWidget()->pos();
+ pw = (this->parentWidget()->width() - f->width()) / 2;
+ ph = (this->parentWidget()->height() - f->height()) / 2;
+ }
+ this->resize(*f);
+ this->setFixedSize(*f);
+ this->setGeometry(pw, ph, f->width(), f->height());
+ });
+}