mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
[autofill] Change saved password when user enters new data.
Closes #734
This commit is contained in:
parent
4fc6686185
commit
0c10211cea
@ -191,6 +191,30 @@ void AutoFill::addEntry(const QUrl &url, const PageFormData &formData)
|
||||
mApp->dbWriter()->executeQuery(query);
|
||||
}
|
||||
|
||||
void AutoFill::updateEntry(const QUrl &url, const PageFormData &formData)
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.prepare("SELECT data FROM autofill WHERE server=?");
|
||||
query.addBindValue(url.host());
|
||||
query.exec();
|
||||
|
||||
if (!query.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString server = url.host();
|
||||
if (server.isEmpty()) {
|
||||
server = url.toString();
|
||||
}
|
||||
|
||||
query.prepare("UPDATE autofill SET data=?, username=?, password=? WHERE server=?");
|
||||
query.addBindValue(formData.postData);
|
||||
query.addBindValue(formData.username);
|
||||
query.addBindValue(formData.password);
|
||||
query.addBindValue(server);
|
||||
mApp->dbWriter()->executeQuery(query);
|
||||
}
|
||||
|
||||
void AutoFill::completePage(WebPage* page)
|
||||
{
|
||||
if (!page) {
|
||||
@ -238,23 +262,32 @@ void AutoFill::post(const QNetworkRequest &request, const QByteArray &outgoingDa
|
||||
return;
|
||||
}
|
||||
|
||||
PageFormCompleter completer(webPage);
|
||||
|
||||
// v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101));
|
||||
// QWebPage::NavigationType type = (QWebPage::NavigationType)v.toInt();
|
||||
|
||||
// if (type != QWebPage::NavigationTypeFormSubmitted) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
const QUrl &siteUrl = webPage->url();
|
||||
const PageFormData &formData = completer.extractFormData(outgoingData);
|
||||
|
||||
if (!isStoringEnabled(siteUrl) || isStored(siteUrl) || !formData.found) {
|
||||
if (!isStoringEnabled(siteUrl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, formData);
|
||||
PageFormCompleter completer(webPage);
|
||||
const PageFormData &formData = completer.extractFormData(outgoingData);
|
||||
|
||||
if (!formData.found) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool updateData = false;
|
||||
if (isStored(siteUrl)) {
|
||||
const QString &user = getUsername(siteUrl);
|
||||
const QString &pass = getPassword(siteUrl);
|
||||
|
||||
if (user == formData.username && pass == formData.password) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateData = true;
|
||||
}
|
||||
|
||||
AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, formData, updateData);
|
||||
webView->addNotification(aWidget);
|
||||
}
|
||||
|
||||
|
@ -44,9 +44,12 @@ public:
|
||||
|
||||
QString getUsername(const QUrl &url);
|
||||
QString getPassword(const QUrl &url);
|
||||
|
||||
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 PageFormData &formData);
|
||||
|
||||
void post(const QNetworkRequest &request, const QByteArray &outgoingData);
|
||||
void completePage(WebPage* frame);
|
||||
|
||||
|
@ -22,9 +22,10 @@
|
||||
#include "animatedwidget.h"
|
||||
#include "iconprovider.h"
|
||||
|
||||
AutoFillNotification::AutoFillNotification(const QUrl &url, const PageFormData &formData)
|
||||
AutoFillNotification::AutoFillNotification(const QUrl &url, const PageFormData &formData, bool updateData)
|
||||
: AnimatedWidget(AnimatedWidget::Down, 300, 0)
|
||||
, ui(new Ui::AutoFillWidget)
|
||||
, m_updateData(updateData)
|
||||
, m_url(url)
|
||||
, m_formData(formData)
|
||||
{
|
||||
@ -43,8 +44,19 @@ AutoFillNotification::AutoFillNotification(const QUrl &url, const PageFormData &
|
||||
userPart = tr("for <b>%1</b>").arg(m_formData.username);
|
||||
}
|
||||
|
||||
ui->label->setText(tr("Do you want QupZilla to remember the password %1 %2?").arg(userPart, hostPart));
|
||||
if (updateData) {
|
||||
ui->label->setText(tr("Do you want QupZilla to update saved password %1?").arg(hostPart));
|
||||
|
||||
ui->remember->setVisible(false);
|
||||
ui->never->setVisible(false);
|
||||
}
|
||||
else {
|
||||
ui->label->setText(tr("Do you want QupZilla to remember the password %1 %2?").arg(userPart, hostPart));
|
||||
|
||||
ui->update->setVisible(false);
|
||||
}
|
||||
|
||||
connect(ui->update, SIGNAL(clicked()), this, SLOT(update()));
|
||||
connect(ui->remember, SIGNAL(clicked()), this, SLOT(remember()));
|
||||
connect(ui->never, SIGNAL(clicked()), this, SLOT(never()));
|
||||
connect(ui->notnow, SIGNAL(clicked()), this, SLOT(hide()));
|
||||
@ -53,6 +65,12 @@ AutoFillNotification::AutoFillNotification(const QUrl &url, const PageFormData &
|
||||
startAnimation();
|
||||
}
|
||||
|
||||
void AutoFillNotification::update()
|
||||
{
|
||||
mApp->autoFill()->updateEntry(m_url, m_formData);
|
||||
hide();
|
||||
}
|
||||
|
||||
void AutoFillNotification::never()
|
||||
{
|
||||
mApp->autoFill()->blockStoringfor(m_url);
|
||||
|
@ -36,16 +36,19 @@ class QT_QUPZILLA_EXPORT AutoFillNotification : public AnimatedWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AutoFillNotification(const QUrl &url, const PageFormData &formData);
|
||||
explicit AutoFillNotification(const QUrl &url,
|
||||
const PageFormData &formData, bool updateData);
|
||||
~AutoFillNotification();
|
||||
|
||||
private slots:
|
||||
void update();
|
||||
void remember();
|
||||
void never();
|
||||
|
||||
private:
|
||||
Ui::AutoFillWidget* ui;
|
||||
|
||||
bool m_updateData;
|
||||
QUrl m_url;
|
||||
PageFormData m_formData;
|
||||
};
|
||||
|
@ -63,6 +63,13 @@
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="update">
|
||||
<property name="text">
|
||||
<string>Update</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="remember">
|
||||
<property name="sizePolicy">
|
||||
|
@ -345,6 +345,10 @@
|
||||
<source>Successfully exported</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>AutoFillNotification</name>
|
||||
@ -360,6 +364,10 @@
|
||||
<source>Do you want QupZilla to remember the password %1 %2?</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Do you want QupZilla to update saved password %1?</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>AutoFillWidget</name>
|
||||
@ -375,6 +383,10 @@
|
||||
<source>Not Now</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Update</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>BookmarkIcon</name>
|
||||
|
Loading…
Reference in New Issue
Block a user