mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +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)
|
||||
{
|
||||
QSqlQuery query;
|
||||
QString server = url.host();
|
||||
if (server.isEmpty()) {
|
||||
server = url.toString();
|
||||
}
|
||||
|
||||
query.prepare("SELECT username FROM autofill WHERE server=?");
|
||||
query.addBindValue(url.host());
|
||||
query.addBindValue(server);
|
||||
query.exec();
|
||||
|
||||
if (query.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString server = url.host();
|
||||
if (server.isEmpty()) {
|
||||
server = url.toString();
|
||||
}
|
||||
|
||||
query.prepare("INSERT INTO autofill (server, username, password) VALUES (?,?,?)");
|
||||
query.bindValue(0, server);
|
||||
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)
|
||||
{
|
||||
QSqlQuery query;
|
||||
QString server = url.host();
|
||||
if (server.isEmpty()) {
|
||||
server = url.toString();
|
||||
}
|
||||
|
||||
query.prepare("SELECT data FROM autofill WHERE server=?");
|
||||
query.addBindValue(url.host());
|
||||
query.addBindValue(server);
|
||||
query.exec();
|
||||
|
||||
if (query.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString server = url.host();
|
||||
if (server.isEmpty()) {
|
||||
server = url.toString();
|
||||
}
|
||||
|
||||
query.prepare("INSERT INTO autofill (server, data, username, password) VALUES (?,?,?,?)");
|
||||
query.bindValue(0, server);
|
||||
query.bindValue(1, formData.postData);
|
||||
|
@ -191,22 +191,45 @@ void AutoFill::addEntry(const QUrl &url, const PageFormData &formData)
|
|||
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;
|
||||
query.prepare("SELECT data FROM autofill WHERE server=?");
|
||||
query.addBindValue(url.host());
|
||||
QString server = url.host();
|
||||
if (server.isEmpty()) {
|
||||
server = url.toString();
|
||||
}
|
||||
|
||||
query.prepare("SELECT username FROM autofill WHERE server=?");
|
||||
query.addBindValue(server);
|
||||
query.exec();
|
||||
|
||||
if (!query.next()) {
|
||||
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();
|
||||
if (server.isEmpty()) {
|
||||
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.addBindValue(formData.postData);
|
||||
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 PageFormData &formData);
|
||||
|
||||
void updateEntry(const QUrl &url, const QString &name, const QString &pass);
|
||||
void updateEntry(const QUrl &url, const PageFormData &formData);
|
||||
|
||||
void post(const QNetworkRequest &request, const QByteArray &outgoingData);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "qupzilla.h"
|
||||
#include "bookmarkstree.h"
|
||||
#include "browsinglibrary.h"
|
||||
#include "bookmarksmanager.h"
|
||||
|
||||
#include <QToolTip>
|
||||
#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(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()
|
||||
|
|
|
@ -283,11 +283,17 @@ void NetworkManager::authentication(QNetworkReply* reply, QAuthenticator* auth)
|
|||
formLa->addRow(save);
|
||||
|
||||
formLa->addWidget(box);
|
||||
bool shouldUpdateEntry = false;
|
||||
AutoFill* fill = mApp->autoFill();
|
||||
QString storedUser;
|
||||
QString storedPassword;
|
||||
if (fill->isStored(reply->url())) {
|
||||
save->setChecked(true);
|
||||
user->setText(fill->getUsername(reply->url()));
|
||||
pass->setText(fill->getPassword(reply->url()));
|
||||
shouldUpdateEntry = true;
|
||||
storedUser = fill->getUsername(reply->url());
|
||||
storedPassword = fill->getPassword(reply->url());
|
||||
user->setText(storedUser);
|
||||
pass->setText(storedPassword);
|
||||
}
|
||||
emit wantsFocus(reply->url());
|
||||
|
||||
|
@ -304,7 +310,14 @@ void NetworkManager::authentication(QNetworkReply* reply, QAuthenticator* auth)
|
|||
auth->setPassword(pass->text());
|
||||
|
||||
if (save->isChecked()) {
|
||||
fill->addEntry(reply->url(), user->text(), pass->text());
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user