mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-14 19:12:11 +01:00
Update HTTP password when needed and remove redundant casting
This commit is contained in:
parent
47eecba4da
commit
396bac50b6
|
@ -146,19 +146,19 @@ QString AutoFill::getPassword(const QUrl &url)
|
||||||
void AutoFill::addEntry(const QUrl &url, const QString &name, const QString &pass)
|
void AutoFill::addEntry(const QUrl &url, const QString &name, const QString &pass)
|
||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
|
QString server = url.host();
|
||||||
|
if (server.isEmpty()) {
|
||||||
|
server = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
query.prepare("SELECT username FROM autofill WHERE server=?");
|
query.prepare("SELECT username FROM autofill WHERE server=?");
|
||||||
query.addBindValue(url.host());
|
query.addBindValue(server);
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
if (query.next()) {
|
if (query.next()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString server = url.host();
|
|
||||||
if (server.isEmpty()) {
|
|
||||||
server = url.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
query.prepare("INSERT INTO autofill (server, username, password) VALUES (?,?,?)");
|
query.prepare("INSERT INTO autofill (server, username, password) VALUES (?,?,?)");
|
||||||
query.bindValue(0, server);
|
query.bindValue(0, server);
|
||||||
query.bindValue(1, name);
|
query.bindValue(1, name);
|
||||||
|
@ -170,19 +170,19 @@ void AutoFill::addEntry(const QUrl &url, const QString &name, const QString &pas
|
||||||
void AutoFill::addEntry(const QUrl &url, const PageFormData &formData)
|
void AutoFill::addEntry(const QUrl &url, const PageFormData &formData)
|
||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
|
QString server = url.host();
|
||||||
|
if (server.isEmpty()) {
|
||||||
|
server = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
query.prepare("SELECT data FROM autofill WHERE server=?");
|
query.prepare("SELECT data FROM autofill WHERE server=?");
|
||||||
query.addBindValue(url.host());
|
query.addBindValue(server);
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
if (query.next()) {
|
if (query.next()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString server = url.host();
|
|
||||||
if (server.isEmpty()) {
|
|
||||||
server = url.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
query.prepare("INSERT INTO autofill (server, data, username, password) VALUES (?,?,?,?)");
|
query.prepare("INSERT INTO autofill (server, data, username, password) VALUES (?,?,?,?)");
|
||||||
query.bindValue(0, server);
|
query.bindValue(0, server);
|
||||||
query.bindValue(1, formData.postData);
|
query.bindValue(1, formData.postData);
|
||||||
|
@ -191,22 +191,45 @@ void AutoFill::addEntry(const QUrl &url, const PageFormData &formData)
|
||||||
mApp->dbWriter()->executeQuery(query);
|
mApp->dbWriter()->executeQuery(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoFill::updateEntry(const QUrl &url, const PageFormData &formData)
|
void AutoFill::updateEntry(const QUrl &url, const QString &name, const QString &pass)
|
||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare("SELECT data FROM autofill WHERE server=?");
|
QString server = url.host();
|
||||||
query.addBindValue(url.host());
|
if (server.isEmpty()) {
|
||||||
|
server = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
query.prepare("SELECT username FROM autofill WHERE server=?");
|
||||||
|
query.addBindValue(server);
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
if (!query.next()) {
|
if (!query.next()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query.prepare("UPDATE autofill SET username=?, password=? WHERE server=?");
|
||||||
|
query.bindValue(0, name);
|
||||||
|
query.bindValue(1, pass);
|
||||||
|
query.bindValue(2, server);
|
||||||
|
mApp->dbWriter()->executeQuery(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoFill::updateEntry(const QUrl &url, const PageFormData &formData)
|
||||||
|
{
|
||||||
|
QSqlQuery query;
|
||||||
QString server = url.host();
|
QString server = url.host();
|
||||||
if (server.isEmpty()) {
|
if (server.isEmpty()) {
|
||||||
server = url.toString();
|
server = url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query.prepare("SELECT data FROM autofill WHERE server=?");
|
||||||
|
query.addBindValue(server);
|
||||||
|
query.exec();
|
||||||
|
|
||||||
|
if (!query.next()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
query.prepare("UPDATE autofill SET data=?, username=?, password=? WHERE server=?");
|
query.prepare("UPDATE autofill SET data=?, username=?, password=? WHERE server=?");
|
||||||
query.addBindValue(formData.postData);
|
query.addBindValue(formData.postData);
|
||||||
query.addBindValue(formData.username);
|
query.addBindValue(formData.username);
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
void addEntry(const QUrl &url, const QString &name, const QString &pass);
|
void addEntry(const QUrl &url, const QString &name, const QString &pass);
|
||||||
void addEntry(const QUrl &url, const PageFormData &formData);
|
void addEntry(const QUrl &url, const PageFormData &formData);
|
||||||
|
|
||||||
|
void updateEntry(const QUrl &url, const QString &name, const QString &pass);
|
||||||
void updateEntry(const QUrl &url, const PageFormData &formData);
|
void updateEntry(const QUrl &url, const PageFormData &formData);
|
||||||
|
|
||||||
void post(const QNetworkRequest &request, const QByteArray &outgoingData);
|
void post(const QNetworkRequest &request, const QByteArray &outgoingData);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "qupzilla.h"
|
#include "qupzilla.h"
|
||||||
#include "bookmarkstree.h"
|
#include "bookmarkstree.h"
|
||||||
#include "browsinglibrary.h"
|
#include "browsinglibrary.h"
|
||||||
|
#include "bookmarksmanager.h"
|
||||||
|
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
|
@ -65,7 +66,7 @@ BookmarksWidget::BookmarksWidget(QupZilla* mainClass, WebView* view, QWidget* pa
|
||||||
|
|
||||||
connect(ui->folder, SIGNAL(activated(int)), this, SLOT(comboItemActive(int)));
|
connect(ui->folder, SIGNAL(activated(int)), this, SLOT(comboItemActive(int)));
|
||||||
connect(m_bookmarksTree, SIGNAL(requestNewFolder(QWidget*, QString*, bool, QString, WebView*)),
|
connect(m_bookmarksTree, SIGNAL(requestNewFolder(QWidget*, QString*, bool, QString, WebView*)),
|
||||||
reinterpret_cast<QObject*>(mApp->browsingLibrary()->bookmarksManager()), SLOT(addFolder(QWidget*, QString*, bool, QString, WebView*)));
|
mApp->browsingLibrary()->bookmarksManager(), SLOT(addFolder(QWidget*, QString*, bool, QString, WebView*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarksWidget::loadBookmark()
|
void BookmarksWidget::loadBookmark()
|
||||||
|
|
|
@ -283,11 +283,17 @@ void NetworkManager::authentication(QNetworkReply* reply, QAuthenticator* auth)
|
||||||
formLa->addRow(save);
|
formLa->addRow(save);
|
||||||
|
|
||||||
formLa->addWidget(box);
|
formLa->addWidget(box);
|
||||||
|
bool shouldUpdateEntry = false;
|
||||||
AutoFill* fill = mApp->autoFill();
|
AutoFill* fill = mApp->autoFill();
|
||||||
|
QString storedUser;
|
||||||
|
QString storedPassword;
|
||||||
if (fill->isStored(reply->url())) {
|
if (fill->isStored(reply->url())) {
|
||||||
save->setChecked(true);
|
save->setChecked(true);
|
||||||
user->setText(fill->getUsername(reply->url()));
|
shouldUpdateEntry = true;
|
||||||
pass->setText(fill->getPassword(reply->url()));
|
storedUser = fill->getUsername(reply->url());
|
||||||
|
storedPassword = fill->getPassword(reply->url());
|
||||||
|
user->setText(storedUser);
|
||||||
|
pass->setText(storedPassword);
|
||||||
}
|
}
|
||||||
emit wantsFocus(reply->url());
|
emit wantsFocus(reply->url());
|
||||||
|
|
||||||
|
@ -304,9 +310,16 @@ void NetworkManager::authentication(QNetworkReply* reply, QAuthenticator* auth)
|
||||||
auth->setPassword(pass->text());
|
auth->setPassword(pass->text());
|
||||||
|
|
||||||
if (save->isChecked()) {
|
if (save->isChecked()) {
|
||||||
|
if (shouldUpdateEntry) {
|
||||||
|
if (storedUser != user->text() || storedPassword != pass->text()) {
|
||||||
|
fill->updateEntry(reply->url(), user->text(), pass->text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
fill->addEntry(reply->url(), user->text(), pass->text());
|
fill->addEntry(reply->url(), user->text(), pass->text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NetworkManager::ftpAuthentication(const QUrl &url, QAuthenticator* auth)
|
void NetworkManager::ftpAuthentication(const QUrl &url, QAuthenticator* auth)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user