1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

[PasswordManager] Added updated member to PasswordEntry struct.

This commit is contained in:
nowrep 2013-05-20 11:05:54 +02:00
parent c7c1002fce
commit 54a3509fcb
10 changed files with 43 additions and 33 deletions

View File

@ -109,7 +109,7 @@ QVector<PasswordEntry> AutoFill::getAllFormData()
return m_manager->getAllEntries(); return m_manager->getAllEntries();
} }
void AutoFill::updateLastUsed(const PasswordEntry &data) void AutoFill::updateLastUsed(PasswordEntry &data)
{ {
m_manager->updateLastUsed(data); m_manager->updateLastUsed(data);
} }
@ -225,20 +225,21 @@ void AutoFill::post(const QNetworkRequest &request, const QByteArray &outgoingDa
return; return;
} }
PasswordEntry updateData = { -1, QString(), QString(), QString(), QByteArray() }; PasswordEntry updateData;
if (isStored(siteUrl)) { if (isStored(siteUrl)) {
const QVector<PasswordEntry> &list = getFormData(siteUrl); const QVector<PasswordEntry> &list = getFormData(siteUrl);
foreach (const PasswordEntry &data, list) { foreach (const PasswordEntry &data, list) {
if (data.username == formData.username) { if (data.username == formData.username) {
updateLastUsed(data); updateData = data;
updateLastUsed(updateData);
if (data.password == formData.password) { if (data.password == formData.password) {
updateData.password.clear();
return; return;
} }
updateData = data;
updateData.username = formData.username; updateData.username = formData.username;
updateData.password = formData.password; updateData.password = formData.password;
updateData.data = formData.postData; updateData.data = formData.postData;

View File

@ -47,7 +47,7 @@ public:
QVector<PasswordEntry> getFormData(const QUrl &url); QVector<PasswordEntry> getFormData(const QUrl &url);
QVector<PasswordEntry> getAllFormData(); QVector<PasswordEntry> getAllFormData();
void updateLastUsed(const PasswordEntry &data); void updateLastUsed(PasswordEntry &data);
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);

View File

@ -128,7 +128,7 @@ void DatabasePasswordBackend::updateEntry(const PasswordEntry &entry)
mApp->dbWriter()->executeQuery(query); mApp->dbWriter()->executeQuery(query);
} }
void DatabasePasswordBackend::updateLastUsed(const PasswordEntry &entry) void DatabasePasswordBackend::updateLastUsed(PasswordEntry &entry)
{ {
QSqlQuery query; QSqlQuery query;
query.prepare("UPDATE autofill SET last_used=strftime('%s', 'now') WHERE id=?"); query.prepare("UPDATE autofill SET last_used=strftime('%s', 'now') WHERE id=?");

View File

@ -32,7 +32,7 @@ public:
void addEntry(const PasswordEntry &entry); void addEntry(const PasswordEntry &entry);
void updateEntry(const PasswordEntry &entry); void updateEntry(const PasswordEntry &entry);
void updateLastUsed(const PasswordEntry &entry); void updateLastUsed(PasswordEntry &entry);
void removeEntry(const PasswordEntry &entry); void removeEntry(const PasswordEntry &entry);
void removeAll(); void removeAll();

View File

@ -35,7 +35,7 @@ public:
virtual void addEntry(const PasswordEntry &entry) = 0; virtual void addEntry(const PasswordEntry &entry) = 0;
virtual void updateEntry(const PasswordEntry &entry) = 0; virtual void updateEntry(const PasswordEntry &entry) = 0;
virtual void updateLastUsed(const PasswordEntry &entry) = 0; virtual void updateLastUsed(PasswordEntry &entry) = 0;
virtual void removeEntry(const PasswordEntry &entry) = 0; virtual void removeEntry(const PasswordEntry &entry) = 0;
virtual void removeAll() = 0; virtual void removeAll() = 0;

View File

@ -22,21 +22,22 @@
#include <QVector> #include <QVector>
static const int passwordEntryVersion = 1; static const int passwordEntryVersion = 2;
QDataStream &operator <<(QDataStream &stream, const PasswordEntry &tab) QDataStream &operator <<(QDataStream &stream, const PasswordEntry &entry)
{ {
stream << passwordEntryVersion; stream << passwordEntryVersion;
stream << tab.host; stream << entry.host;
stream << tab.id; stream << entry.id;
stream << tab.username; stream << entry.username;
stream << tab.password; stream << entry.password;
stream << tab.data; stream << entry.data;
stream << entry.updated;
return stream; return stream;
} }
QDataStream &operator >>(QDataStream &stream, PasswordEntry &tab) QDataStream &operator >>(QDataStream &stream, PasswordEntry &entry)
{ {
int version; int version;
stream >> version; stream >> version;
@ -45,11 +46,12 @@ QDataStream &operator >>(QDataStream &stream, PasswordEntry &tab)
return stream; return stream;
} }
stream >> tab.host; stream >> entry.host;
stream >> tab.id; stream >> entry.id;
stream >> tab.username; stream >> entry.username;
stream >> tab.password; stream >> entry.password;
stream >> tab.data; stream >> entry.data;
stream >> entry.updated;
return stream; return stream;
} }
@ -98,7 +100,7 @@ void PasswordManager::updateEntry(const PasswordEntry &entry)
m_backend->updateEntry(entry); m_backend->updateEntry(entry);
} }
void PasswordManager::updateLastUsed(const PasswordEntry &entry) void PasswordManager::updateLastUsed(PasswordEntry &entry)
{ {
ensureLoaded(); ensureLoaded();
m_backend->updateLastUsed(entry); m_backend->updateLastUsed(entry);

View File

@ -33,6 +33,9 @@ struct QT_QUPZILLA_EXPORT PasswordEntry {
QString username; QString username;
QString password; QString password;
QByteArray data; QByteArray data;
int updated;
PasswordEntry() : updated(-1) { }
bool isValid() const { bool isValid() const {
return !password.isEmpty(); return !password.isEmpty();
@ -42,8 +45,12 @@ struct QT_QUPZILLA_EXPORT PasswordEntry {
return id == other.id; return id == other.id;
} }
friend QT_QUPZILLA_EXPORT QDataStream &operator<<(QDataStream &stream, const PasswordEntry &tab); bool operator<(const PasswordEntry &other) const {
friend QT_QUPZILLA_EXPORT QDataStream &operator>>(QDataStream &stream, PasswordEntry &tab); return updated > other.updated;
}
friend QT_QUPZILLA_EXPORT QDataStream &operator<<(QDataStream &stream, const PasswordEntry &entry);
friend QT_QUPZILLA_EXPORT QDataStream &operator>>(QDataStream &stream, PasswordEntry &entry);
}; };
class QT_QUPZILLA_EXPORT PasswordManager : public QObject class QT_QUPZILLA_EXPORT PasswordManager : public QObject
@ -60,7 +67,7 @@ public:
void addEntry(const PasswordEntry &entry); void addEntry(const PasswordEntry &entry);
void updateEntry(const PasswordEntry &entry); void updateEntry(const PasswordEntry &entry);
void updateLastUsed(const PasswordEntry &entry); void updateLastUsed(PasswordEntry &entry);
void removeEntry(const PasswordEntry &entry); void removeEntry(const PasswordEntry &entry);
void removeAllEntries(); void removeAllEntries();

View File

@ -1,6 +1,6 @@
include(../../defines.pri) include(../../defines.pri)
contains(DEFINES, "KDE_INTEGRATION") { !mac:unix:contains(DEFINES, "KDE_INTEGRATION") {
TARGET = $$qtLibraryTarget(KWalletPasswords) TARGET = $$qtLibraryTarget(KWalletPasswords)
SOURCES += kwalletplugin.cpp \ SOURCES += kwalletplugin.cpp \

View File

@ -107,22 +107,22 @@ void KWalletPasswordBackend::updateEntry(const PasswordEntry &entry)
} }
} }
void KWalletPasswordBackend::updateLastUsed(const PasswordEntry &entry) void KWalletPasswordBackend::updateLastUsed(PasswordEntry &entry)
{ {
initialize(); initialize();
QString id = QString("%1/%2").arg(entry.host, QString::number(QDateTime::currentDateTime().toTime_t())); QString id = QString("%1/%2").arg(entry.host, QString::number(QDateTime::currentDateTime().toTime_t()));
PasswordEntry stored = entry;
stored.id = id;
m_wallet->removeEntry(entry.id.toString()); m_wallet->removeEntry(entry.id.toString());
m_wallet->writeEntry(stored.id.toString(), encodeEntry(stored));
int index = m_allEntries.indexOf(entry); int index = m_allEntries.indexOf(entry);
entry.id = id;
m_wallet->writeEntry(entry.id.toString(), encodeEntry(entry));
if (index > -1) { if (index > -1) {
m_allEntries[index] = stored; m_allEntries[index] = entry;
} }
} }

View File

@ -37,7 +37,7 @@ public:
void addEntry(const PasswordEntry &entry); void addEntry(const PasswordEntry &entry);
void updateEntry(const PasswordEntry &entry); void updateEntry(const PasswordEntry &entry);
void updateLastUsed(const PasswordEntry &entry); void updateLastUsed(PasswordEntry &entry);
void removeEntry(const PasswordEntry &entry); void removeEntry(const PasswordEntry &entry);
void removeAll(); void removeAll();