Validate domain names, allow saving login data
This commit is contained in:
parent
2216fedeaa
commit
dc0e633e46
@ -4,7 +4,7 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
Configurator::Configurator(int &argc, char **&argv):QApplication(argc, argv),_nam(this) {
|
Configurator::Configurator(int &argc, char **&argv):QApplication(argc, argv),_nam(this),_settings("federated.computer", "configurator", this) {
|
||||||
setQuitOnLastWindowClosed(false);
|
setQuitOnLastWindowClosed(false);
|
||||||
_loginDialog = new FederatedLogin(0);
|
_loginDialog = new FederatedLogin(0);
|
||||||
_loginDialog->setModal(true);
|
_loginDialog->setModal(true);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
#include <dialogs/FederatedLogin.h>
|
#include <dialogs/FederatedLogin.h>
|
||||||
#include <lib/Service.h>
|
#include <lib/Service.h>
|
||||||
@ -18,10 +19,12 @@ public:
|
|||||||
QByteArray download(QUrl const &url);
|
QByteArray download(QUrl const &url);
|
||||||
void waitForDownload(QNetworkReply *r) const;
|
void waitForDownload(QNetworkReply *r) const;
|
||||||
Services const &services() const { return _services; }
|
Services const &services() const { return _services; }
|
||||||
|
QSettings &settings() { return _settings; }
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
void loginRequested();
|
void loginRequested();
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager _nam;
|
QNetworkAccessManager _nam;
|
||||||
|
QSettings _settings;
|
||||||
FederatedLogin * _loginDialog;
|
FederatedLogin * _loginDialog;
|
||||||
Services _services;
|
Services _services;
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "FederatedLogin.h"
|
#include "FederatedLogin.h"
|
||||||
|
#include "DomainValidator.h"
|
||||||
|
#include <Configurator.h>
|
||||||
|
|
||||||
FederatedLogin::FederatedLogin(QWidget *parent):QDialog(parent),_layout(this) {
|
FederatedLogin::FederatedLogin(QWidget *parent):QDialog(parent),_layout(this) {
|
||||||
int y = 0;
|
int y = 0;
|
||||||
@ -7,20 +9,23 @@ FederatedLogin::FederatedLogin(QWidget *parent):QDialog(parent),_layout(this) {
|
|||||||
_layout.addWidget(_message, y, 0, 1, 2);
|
_layout.addWidget(_message, y, 0, 1, 2);
|
||||||
_domainLbl = new QLabel(tr("&Domain:"), this);
|
_domainLbl = new QLabel(tr("&Domain:"), this);
|
||||||
_layout.addWidget(_domainLbl, ++y, 0);
|
_layout.addWidget(_domainLbl, ++y, 0);
|
||||||
_domain = new QLineEdit("f11890a1.fedcom.net", this);
|
_domain = new QLineEdit(app->settings().value("domain").toString(), this);
|
||||||
|
_domain->setValidator(new DomainValidator(_domain));
|
||||||
_domainLbl->setBuddy(_domain);
|
_domainLbl->setBuddy(_domain);
|
||||||
_layout.addWidget(_domain, y, 1);
|
_layout.addWidget(_domain, y, 1);
|
||||||
_userLbl = new QLabel(tr("&User/Email:"), this);
|
_userLbl = new QLabel(tr("&User/Email:"), this);
|
||||||
_layout.addWidget(_userLbl, ++y, 0);
|
_layout.addWidget(_userLbl, ++y, 0);
|
||||||
_user = new QLineEdit(this);
|
_user = new QLineEdit(app->settings().value("user").toString(), this);
|
||||||
_userLbl->setBuddy(_user);
|
_userLbl->setBuddy(_user);
|
||||||
_layout.addWidget(_user, y, 1);
|
_layout.addWidget(_user, y, 1);
|
||||||
_passwordLbl = new QLabel(tr("&Password:"), this);
|
_passwordLbl = new QLabel(tr("&Password:"), this);
|
||||||
_layout.addWidget(_passwordLbl, ++y, 0);
|
_layout.addWidget(_passwordLbl, ++y, 0);
|
||||||
_password = new QLineEdit(this);
|
_password = new QLineEdit(app->settings().value("password").toString(), this);
|
||||||
_password->setEchoMode(QLineEdit::Password);
|
_password->setEchoMode(QLineEdit::Password);
|
||||||
_passwordLbl->setBuddy(_password);
|
_passwordLbl->setBuddy(_password);
|
||||||
_layout.addWidget(_password, y, 1);
|
_layout.addWidget(_password, y, 1);
|
||||||
|
_storeLogin = new QCheckBox(tr("&Store authentication information for next login"), this);
|
||||||
|
_layout.addWidget(_storeLogin, ++y, 0, 1, 2);
|
||||||
_buttons = new ButtonRow(this);
|
_buttons = new ButtonRow(this);
|
||||||
_layout.addWidget(_buttons, ++y, 0, 1, 2);
|
_layout.addWidget(_buttons, ++y, 0, 1, 2);
|
||||||
_ok = new QPushButton(tr("&OK"), _buttons);
|
_ok = new QPushButton(tr("&OK"), _buttons);
|
||||||
@ -28,6 +33,7 @@ FederatedLogin::FederatedLogin(QWidget *parent):QDialog(parent),_layout(this) {
|
|||||||
_buttons->add(_ok);
|
_buttons->add(_ok);
|
||||||
_cancel = new QPushButton(tr("&Cancel"), _buttons);
|
_cancel = new QPushButton(tr("&Cancel"), _buttons);
|
||||||
_buttons->add(_cancel);
|
_buttons->add(_cancel);
|
||||||
|
connect(_ok, &QPushButton::clicked, this, &FederatedLogin::storeLogin);
|
||||||
connect(_ok, &QPushButton::clicked, this, &QDialog::accept);
|
connect(_ok, &QPushButton::clicked, this, &QDialog::accept);
|
||||||
connect(_cancel, &QPushButton::clicked, this, &QDialog::reject);
|
connect(_cancel, &QPushButton::clicked, this, &QDialog::reject);
|
||||||
}
|
}
|
||||||
@ -36,3 +42,11 @@ void FederatedLogin::setMessage(QString const &m) {
|
|||||||
_message->setText(m);
|
_message->setText(m);
|
||||||
_message->setHidden(m.isEmpty());
|
_message->setHidden(m.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FederatedLogin::storeLogin() {
|
||||||
|
if(_storeLogin->isChecked()) {
|
||||||
|
app->settings().setValue("domain", _domain->text());
|
||||||
|
app->settings().setValue("user", _user->text());
|
||||||
|
app->settings().setValue("password", _password->text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
#include <QCheckBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
#include "../lib/ButtonRow.h"
|
#include "../lib/ButtonRow.h"
|
||||||
@ -16,6 +17,8 @@ public:
|
|||||||
QString user() const { return _user->text(); }
|
QString user() const { return _user->text(); }
|
||||||
QString password() const { return _password->text(); }
|
QString password() const { return _password->text(); }
|
||||||
void setMessage(QString const &m);
|
void setMessage(QString const &m);
|
||||||
|
protected Q_SLOTS:
|
||||||
|
void storeLogin();
|
||||||
protected:
|
protected:
|
||||||
QGridLayout _layout;
|
QGridLayout _layout;
|
||||||
QLabel * _message;
|
QLabel * _message;
|
||||||
@ -25,6 +28,7 @@ protected:
|
|||||||
QLineEdit * _user;
|
QLineEdit * _user;
|
||||||
QLabel * _passwordLbl;
|
QLabel * _passwordLbl;
|
||||||
QLineEdit * _password;
|
QLineEdit * _password;
|
||||||
|
QCheckBox * _storeLogin;
|
||||||
ButtonRow * _buttons;
|
ButtonRow * _buttons;
|
||||||
QPushButton * _ok;
|
QPushButton * _ok;
|
||||||
QPushButton * _cancel;
|
QPushButton * _cancel;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
include_directories(${CMAKE_SOURCE_DIR})
|
include_directories(${CMAKE_SOURCE_DIR})
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
add_library(fed STATIC Service.cpp ButtonRow.cpp ServiceWidget.cpp)
|
add_library(fed STATIC Service.cpp ButtonRow.cpp ServiceWidget.cpp DomainValidator.cpp)
|
||||||
target_link_libraries(fed Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets Qt${QT_VERSION}::Network)
|
target_link_libraries(fed Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets Qt${QT_VERSION}::Network)
|
||||||
|
4
lib/DomainValidator.cpp
Normal file
4
lib/DomainValidator.cpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#include "DomainValidator.h"
|
||||||
|
|
||||||
|
DomainValidator::DomainValidator(QObject * parent):QRegularExpressionValidator(QRegularExpression("^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,63}$"), parent) {
|
||||||
|
}
|
10
lib/DomainValidator.h
Normal file
10
lib/DomainValidator.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QRegularExpressionValidator>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
class DomainValidator:public QRegularExpressionValidator {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DomainValidator(QObject * parent = nullptr);
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user