aboutsummaryrefslogtreecommitdiff
path: root/sb.cpp
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-01-28 22:57:03 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2023-01-28 22:57:03 +0100
commitf25f28827639da3eb54f0e4a85174fe2cc777dcb (patch)
treef631fd6dab840f11c3ac9e17e016bc9ce73ada58 /sb.cpp
parente651d2636724cd6c5a55f3847d275f9be620db47 (diff)
add simple authentification for http sitesHEADmaster
Diffstat (limited to 'sb.cpp')
-rw-r--r--sb.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/sb.cpp b/sb.cpp
index 0823c4c..c4562b0 100644
--- a/sb.cpp
+++ b/sb.cpp
@@ -3,7 +3,9 @@
#include <QtWidgets/QApplication>
#include <QAction>
+#include <QAuthenticator>
#include <QtGui/QWindow>
+#include <QDialog>
#include <QtWidgets/QMainWindow>
#include <QtWebEngineWidgets/QWebEngineView>
#include <QWebEngineView>
@@ -19,6 +21,8 @@
#include <X11/Xlib.h>
#include <QShortcut>
#include <QVBoxLayout>
+#include <QLineEdit>
+#include <QPushButton>
bool is_valid_url(const std::string & url);
@@ -246,6 +250,46 @@ main(int argc, char **argv) {
}
});
+ web->page()->connect(web->page(), &QWebEnginePage::authenticationRequired, [&](const QUrl &url, QAuthenticator *authenticator) {
+ QDialog dialog;
+ QVBoxLayout layout;
+ QLineEdit user;
+ QLineEdit password;
+ QPushButton ok;
+ QPushButton cancel;
+
+ ok.setText("Ok");
+ cancel.setText("Cancel");
+ user.setPlaceholderText("Username");
+ password.setPlaceholderText("Password");
+ password.setEchoMode(QLineEdit::Password);
+
+ dialog.setLayout(&layout);
+ layout.addWidget(&user);
+ layout.addWidget(&password);
+ layout.addWidget(&ok);
+ layout.addWidget(&cancel);
+
+ dialog.connect(&dialog, &QDialog::finished, [&](int result) {
+ if (result == QDialog::Accepted) {
+ authenticator->setUser(user.text());
+ authenticator->setPassword(password.text());
+ }
+ dialog.close();
+ });
+
+ ok.connect(&ok, &QPushButton::pressed, [&]() {
+ dialog.accept();
+ });
+
+ cancel.connect(&cancel, &QPushButton::pressed, [&]() {
+ web->stop();
+ dialog.reject();
+ });
+
+ dialog.exec();
+ });
+
register_shortcuts(view);
return app.exec();